Building Sytem YOU will be able to build and delete blocks in your battle royale games with a building system.. Activity 1 2 | C o d e N i n j a s R o b l o x B a t t l e R o y a l e 1 We are going to add a pickaxe and a sledgehammer from the toolbox into the S tarter Pack. 2 We going to add and customize a local script for the pickaxe to make blocks and add a local script for the hammer to delete blocks. Rename the script for the pickaxe create and the script for the sledgehammer destroy. 2a Add a local script in the pick axe object by click on the add icon and rename it to “ Create ”. 2b Add a local script in the sledgehammer object by click on the add icon and rename it to “ Destroy ”. C o p y r i g h t © C o d e N i n j a s L L C | 3 3 Now, lets go ahead and setup the script pickaxe first because we want to build from the Artec Freestyle blocks we’ve set up. 3a Add 3 local variables. local player = game.Players.LocalPlayer local mouse = player:GetMouse() local offset = Vector3.new(0,2,0) 4 Next, create a function to where if the tool we are using is activated we will create new blocks in the workspace. 4a So, below all the local variables add a new function to where the tool we are using is activated, execute the script. script.Parent.Activated:Connect(function () end) 4 b Inside the function we are going to add a conditional if where we click in the area the mouse is not the target. if not mouse.Target then return end 4 | C o d e N i n j a s R o b l o x B a t t l e R o y a l e 4c Next, we add a local variable to where did we click. local clickPosition = mouse.Hit.Position 4d Add a local variable to how far away we click. local distanceToObject = player:DistanceFromCharacter(clickPosition) block to another block, then we will end 4e Now, we add another conditional to where if we are too far away to attach a if distanceToObject > 10 then end 4f Add another local variable to create a clone of blocks in the workspace local newBlock = workspace.Block:Clone() 4g Now, we give our cloned block to the workspace as a child object newBlock.Parent = workspace C o p y r i g h t © C o d e N i n j a s L L C | 5 6 | C o d e N i n j a s R o b l o x B a t t l e R o y a l e 4h Now, we are going to move our cloned block to the mouse location and make sure it sits nicely on the ground newBlock.Position = mouseToGrid(clickPosition) 5 Now that we created a function to create cloned blocks to the workspace, we now need a function to get the grid position. 5 a So below the script function, lets add a function for a grid position and place variables inside the parenthesis. function getGridPosition(pos, gridWidth) end 5b Next, we add a local variable that equal to an interger local x = math.floor(pos) 5c Add another local variable that equal to the x position and grid width local xr = math.fmod(x, gridWidth) 5d Finally, we return the value of local x variable and local xr variable return x – xr 6 We need to add one more function for the position on the X, Y, Z axis . It’ll be the click position for the placement of the cloned blocks. 6a Under the getGridPosition function add another function. Inside the parenthesis, we insert the local variable clickPosition. function mouseToGrid(clickPosition) end 6b Now, inside the function we will add a line for return the position of the click position and grid position. We will also add an offset. return Vector3.new(getGridPosition(clickPosition.x, 4), getGridPosition(clickPosition.y, 4), getGridPosition(clickPosition.z, 4)) + offset C o p y r i g h t © C o d e N i n j a s L L C | 7 8 | C o d e N i n j a s R o b l o x B a t t l e R o y a l e create blocks next to each other and even in mid air. 7 Lets test out the pickaxe to see if we can create blocks. 7a Click the play button 7b Click the Pickaxe icon 7c Click the l eft mouse button 7d As you can see we can create and stack blocks on top of each other. We can lines for deleting the cloned block objects. 8 Now, lets open the local script in the sledgehammer and lets start add new 8a Lets start by adding 2 variables for the player and the mouse. local player = game.Players.LocalPlayer local mouse = player:GetMouse() 9 Now we need to add a function for when the tool is in use activated the function. 9a Below the local variables , create a function for the script activation. script.Parent.Activated:Connect(function() end) area the mouse is not the target. 9b Inside the function we are going to add a conditional if where we click in the if not mouse.Target then return end 9c Next, we add a local variable to where did we click. local clickPosition = mouse.Hit.Position C o p y r i g h t © C o d e N i n j a s L L C | 9 10 | C o d e N i n j a s R o b l o x B a t t l e R o y a l e 9d Add a local variable to how far away we click. local distanceToObject = player:DistanceFromCharacter(clickPosition) block to another block, then we will end 9e Now, we add another conditional to where if we are too far away to attach a if distanceToObject > 10 then end 9f Finally we add a conditional here if object we are targeting is the block object and our distance is less than a set value , we delete the object. I f mouse.Target.Name == “Block’ and distanceToObject < 10 then mouse.Target:Destroy() end created. 10 Now, test out the sledgehammer to see if it deletes the blocks you’ve button 10a Click the play button 10b Create a block using the pickaxe 10c Next, use the Sledgehammer to delete the block by using the left mouse 10d Now, if you have deleted the block, then that means you can build and delete blocks. time to incorpreate them when the game is ready. 11 Now, that we have setup the pickaxe and the sledgehammer to work, now its C o p y r i g h t © C o d e N i n j a s L L C | 11 12 | C o d e N i n j a s R o b l o x B a t t l e R o y a l e 11a Move the pickaxe and sledgehammer to the Server Storage pickaxe and sledgehammer along with the sword. 12 Now, its time to add local variables to Player Manager , so we can use the script. 12a Go to the ModuleScripts folder in ServerStorage . Open the PlayerManager 12b Now under the comments, Player variables , we are going to add two more variables. We are going to keep the local variables in numbered ordered that way we can spawn into the game with all the tools we need. local playerWeapon1 = ServerStorage.Weapon local playerWeapon2 = ServerStorage.Pickaxe local playerWeapon3 = ServerStorage.Sledgehammer 12c Inside the l ocal function prepare player we need to adjust and add all of the player variables . So, when the game is ready we need to load the player with clones of the tools as child objects. local weapon = playerWeapon1:Clone() local pickaxe = playerWeapon2:Clone() local sledgehammer = playerWeapon3:Clone() weapon.Parent = character pickaxe.Parent = character sledgehammer.Parent = character C o p y r i g h t © C o d e N i n j a s L L C | 1 3 14 | C o d e N i n j a s R o b l o x B a t t l e R o y a l e 12d Now, inside the removePlayerWeapon , we need to remove the Pickaxe a nd Sledgehammer when the player is disconnected or have been eliminated from the game. if character:FindFirstChild("Pickaxe") then character.Pickaxe:Destroy() end if whichPlayer.Backpack:FindFirstChild("Pickaxe") then whichPlayer.Backpack.Pickaxe:Destroy() end if character:FindFirstChild("Sledgehammer") then character.Pickaxe:Destroy() end if whichPlayer.Backpack:FindFirstChild("Sledgehammer") then whichPlayer.Backpack.Pickaxe:Destroy() end 13 Now, its time to test if the player has tools when the game starts. 13a Click on the Start button in the Test panel 13b Now, the players will spawn into the game with tools in their possession C o p y r i g h t © C o d e N i n j a s L L C | 1 5 Weapon Giver YOU will be able to distribute weapons in your battle royale games. 1 We are going to add a spawner that will give weapons to players. For, this lesson you can use any weapon you want. Make sure that weapon you choose is fully operational. Activity 2 1 7 | C o d e N i n j a s R o b l o x B a t t l e R o y a l e 2 The first thing we need to add is a part. Like a platform that will act a s if the weapon i s floating from the platform. 2a Click on part and select Cylinder 2b Rotate the cylinder using the blue sphere until the cylinder is vertical at 90 degree . Use the move tool to move the cylinder upward if it doesn’t rotate on the ground. coordinates to adjust your cylinder in the properties menu 2c Now, resize the object using the scale tool . You can also use the size C o p y r i g h t © C o d e N i n j a s L L C | 1 8 1 9 | C o d e N i n j a s R o b l o x B a t t l e R o y a l e 2d Place it on the ground using the move tool 3 Now, that we have setup the platform we now need to add the w eapon we want to give to players. Before you use any weapon, lets use 1 weapon to test to see if the weapon spawner works. 3a Go to the tool and search for Orange Hyperlaser