Activity 1 Building Sytem YOU will be able to build and delete blocks in your battle royale games with a building system.. 1 We are going to add a pickaxe and a sledgehammer from the toolbox into the Starter 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”. 2|Code Ninjas Roblox Battle Royale 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) 4b 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 C o p y r i g h t © C o d e N i n j a s L L C |3 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) 4e Now, we add another conditional to where if we are too far away to attach a block to another block, then we will end if distanceToObject > 10 then end 4|Code Ninjas Roblox Battle Royale 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 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. 5a 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) 6|Code Ninjas Roblox Battle Royale 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 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 left mouse button. 7d As you can see we can create and stack blocks on top of each other. We can create blocks next to each other and even in mid air. 8 Now, lets open the local script in the sledgehammer and lets start add new lines for deleting the cloned block objects. 8a Lets start by adding 2 variables for the player and the mouse. local player = game.Players.LocalPlayer local mouse = player:GetMouse() 8|Code Ninjas Roblox Battle Royale 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) 9b 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 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 9d Add a local variable to how far away we click. local distanceToObject = player:DistanceFromCharacter(clickPosition) 9e Now, we add another conditional to where if we are too far away to attach a block to another block, then we will end if distanceToObject > 10 then end 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 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. If mouse.Target.Name == “Block’ and distanceToObject < 10 then mouse.Target:Destroy() end 10 Now, test out the sledgehammer to see if it deletes the blocks you’ve created. 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 button. 10d Now, if you have deleted the block, then that means you can build and delete blocks. 11 Now, that we have setup the pickaxe and the sledgehammer to work, now its time to incorpreate them when the game is ready. C o p y r i g h t © C o d e N i n j a s L L C | 11 11a Move the pickaxe and sledgehammer to the Server Storage. 12 Now, its time to add local variables to Player Manager, so we can use the pickaxe and sledgehammer along with the sword. 12a Go to the ModuleScripts folder in ServerStorage. Open the PlayerManager script. 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 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 local 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 | 13 12d Now, inside the removePlayerWeapon, we need to remove the Pickaxe and 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. 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 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 | 15 Activity 2 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. 2 The first thing we need to add is a part. Like a platform that will act as if the weapon is 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. 17|Code Ninjas Roblox Battle Royale 2c Now, resize the object using the scale tool. You can also use the size coordinates to adjust your cylinder in the properties menu. C o p y r i g h t © C o d e N i n j a s L L C | 18 2d Place it on the ground using the move tool. 3 Now, that we have setup the platform we now need to add the weapon 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. 19|Code Ninjas Roblox Battle Royale 3b Add the weapon to the workspace instead of the starterpack. 3c Position the weapon in the middle of the platform using the move tool. 4 Now, its to use dupllicate one of the child object parts in the tool . We basically use it to spawn the weapon. C o p y r i g h t © C o d e N i n j a s L L C | 20 4a Click on the arrow next to the orange laser tool. Then, duplicate the handle. You should have two handles. 4b Now, move the one of the handles to the workspace. 4c With the object still selected, in the properties panel scroll to Behavior. Turn on Anchored. 21|Code Ninjas Roblox Battle Royale 4d Turn off CanCollide. 4e Now, move the laser tool to the replicated storage. 5 Now its time that we start scripting our weapon spawner. Before we do that we just need to group just two objects together. 5a Select the Handle and Part with CTRL keyboard button. Then, right click and select group. C o p y r i g h t © C o d e N i n j a s L L C | 21 5b Select the handle and add a script. 5c Lets open the script and start programming the weapon. First thing we need to do is add 2 local variables. 1 for the weapon we are going to be using and the other as a boolean to see if the weapon spawner is disabled or not. local weapon = game:GetService(“ReplicatedStorage”):WaitForChild(“LaserGun”) local weaponSpawnDisabled = true 6 Now, its time to add a function to where the if the player touches the weapon, it will add a lasergun to the players backpack. 23|Code Ninjas Roblox Battle Royale 6a Under the local variables, add a touched function for weapon. script.Parent.Touched:Connect(function(weapo n) end) 6b Add a conditional for if the weapon is being add to a humanoid as a child object. If part.Parent:FindFirstChild(“Humanoid”) ~= nil then end 6c Inside the conditional, add a local variable for all the players in game. local player = game.Players:GetPlayerFromCharacter(weapon.Parent) C o p y r i g h t © C o d e N i n j a s L L C | 24 6d Below the local variable, lets add a conditional for the player. if player ~= nil then end 6e Now add another conditional to where if the player has a backpack if player.Backpack ~= nil then end 6f One more conditional for if the weapon spawn is disabled. if weaponSpawnDisabled == true then end 25|Code Ninjas Roblox Battle Royale 7 Inside that last conditional statement, we just need to add a couple of things especially when it comes to enabling the weapon spawner 7a First, we are going to make the boolean weaponSpawnDisabled equal to false. weaponSpawnDisabled = false 7b Now, we are going to add the weapon as a cloned object to the player’s backpack. weapon:Clone().Parent = player.Backpack C o p y r i g h t © C o d e N i n j a s L L C | 26 7c Add a 1 second wait, then we make the boolean weaponSpawnDisabled to equal to true. wait(1) weaponSpawnDisabled = true 8 Now test the game to see if the there is a cloned orange laser gun in your backpack. 27|Code Ninjas Roblox Battle Royale 9 Once last thing we are going to do is make the laser gun rotate in the middle of the platform. 9a Go back to the script and below the function, add a while true do function. while true do end 9b Now, to make the object we are going to add a line to where the object rotates every second on the Y axis. script.Parent.CFrame = script.Parent.CFrame * CFrame.Angles(0,0.05,0) 10 Now play test your scene and you will see that your object rotate. C o p y r i g h t © C o d e N i n j a s L L C | 28 Activity 3 Jump Powerup YOU will be able to boost player jump in your battle royale games 1 We are going to add insert a model from the toolbox that will act as a powerup. 1a Go to the toolbox and search for a Gem. 1b Add the Gem into the workspace 1c Rename the Gem to PowerUpJump, You can rename the object by right clicking and select rename. You can also go to the properties and rename the object in the data panel. 30|Code Ninjas Roblox Battle Royale 1d Add a script in the Gem as a child object. 1d Change the object color to any color of your choosing. C o p y r i g h t © C o d e N i n j a s L L C | 31 2 Now, lets script the Gem to where it will act as a powerup. 2a First lets add a local variable for the script local powerupJump = script.Parent 3 Now, we need a function to where the object is touched execute the code inside. script.Parent.Touched:connect(function(powerup) end) 32|Code Ninjas Roblox Battle Royale 3a Now, inside the function lets add a conditional to where if the object is a humanoid. if powerup.Parent:FindFirstChild("Humanoid") then end 3b Now, lets increase the player jump by at least 100. Now, you change the value to whatever you want it to be, but the player must stay visible in the game. powerup.Parent.Humanoid.JumpPower = 100 3c When the player touches the gem it will destroy the object, but it will not change the value. So, lets add the variable to with a Destroy function. powerupJump:Destroy() C o p y r i g h t © C o d e N i n j a s L L C | 33 3d Add a wait time for 5 seconds. You can add more seconds to the script, but don’t keep it too long. wait(5) 3e After the time has expired for the powerup, reset it to its original value. So, for the original value lets set the jump power to 50. powerup.Parent.Humanoid.JumpPower = 50 4 Now,its time to test if the power up works. 34|Code Ninjas Roblox Battle Royale 4a Click the play button. 4b Now, run into the power up and you’ll see that player speed increased C o p y r i g h t © C o d e N i n j a s L L C | 35 Activity 4 Speed Powerup YOU will be able to boost player speed in your battle royale games 1 We are going to add insert a model from the toolbox that will act as a powerup. 1a Go to the toolbox and search for a Gem. 1b Add the Gem into the workspace 1c Add a script in the Gem as a child object. 1d Change the object color to any color of your choosing. 37|Code Ninjas Roblox Battle Royale 2 Now, lets script the Gem to where it will act as a powerup. 2a First lets add a local variable for the script local powerupSpeed= script.Parent 3 Now, we need a function to where the object is touched execute the code inside. script.Parent.Touched:connect(function(powerup) end) C o p y r i g h t © C o d e N i n j a s L L C | 38 3a Now, inside the function lets add a conditional to where if the object is a humanoid. if powerup.Parent:FindFirstChild("Humanoid") then end 3b Now, lets increase the player jump by at least 100. Now, you change the value to whatever you want it to be, but the player must stay visible in the game. powerup.Parent.Humanoid.WalkSpeed = 50 3c When the player touches the gem it will destroy the object, but it will not change the value. So, lets add the variable to with a Destroy function. powerupSpeed:Destroy() 39|Code Ninjas Roblox Battle Royale
Enter the password to open this PDF file:
-
-
-
-
-
-
-
-
-
-
-
-