How could I add a bit where it gives you a knife when you are teleported into a map?

Hey guys, how would I configure this script so to add a part where you get a knife when you are teleported into a map? Heres my code-

ServerStorage = game:GetService("ServerStorage")
ReplicatedStorage = game:GetService("ReplicatedStorage")
Players = game:GetService("Players")

Maps = ServerStorage:WaitForChild('Maps'):GetChildren()
Status = ReplicatedStorage:WaitForChild('Status')

while true do
	
	--Intermission
	
	local Countdown = 30 -- intermission, make this as long as you want
	
	repeat wait(1)
		Countdown = Countdown - 1
		
		Status.Value = 'Intermission : '..Countdown
	until Countdown <= 0
	
	--Choose the map.
	
	Status.Value = 'Choosing Map...'
	
	local ChosenMap = Maps[math.random(1, #Maps)]:Clone()
	local Spawns = ChosenMap:FindFirstChild('Spawns'):GetChildren()
	local RandomSpawn = Spawns[math.random(1, #Spawns)]
	
	wait(5) -- little pause, make this as long as you want
	
	ChosenMap.Parent = workspace
	Status.Value = 'Map chosen, teleporting players.'
	
	wait(2) -- little pause, make this as long as you want
	
	--teleport the players
	
	for _, Player in pairs(Players:GetChildren())do
		if Player.Character and Player.Character:FindFirstChild('Humanoid') then
			Player.Character.HumanoidRootPart.CFrame = RandomSpawn.CFrame
		end
	end
	
	Countdown = 5 -- Starting Round In, make this as long as you want
	
	repeat wait(1)
		Countdown = Countdown - 1
		
		Status.Value = 'Starting Round in : '..Countdown
	until Countdown <= 0
	
	Countdown = 60 -- Game Time
	
	repeat wait(1)
		Countdown = Countdown - 1
		
		Status.Value = 'Ingame : '..Countdown
	until Countdown <= 0
	
	--Kill the players
	
	for _, Player in pairs(Players:GetChildren())do
		if Player.Character and Player.Character:FindFirstChild('Humanoid') then
			Player.Character.Humanoid:TakeDamage(2000)
		end
	end
	
	ChosenMap:Destroy()
	
	Status.Value = 'Round Ended, waiting for new game.'
	
	wait(4) -- little pause, make this as long as you want.
	
end

--By octavodad!

Thanks!

Hey There,
As I understand it, you are asking how you would add a knife into the player’s backpack? This only requires you to add a few lines to your already existing code. You have the line that loops through your players. Within that loop is the best place to do it.
Here is a descriptive guide on doing that.

`teleport the players 

--THIS line will be where you find the knife in ServerStorage

	for _, Player in pairs(Players:GetChildren())do
		if Player.Character and Player.Character:FindFirstChild('Humanoid') then
			Player.Character.HumanoidRootPart.CFrame = RandomSpawn.CFrame

--THIS is where you want to add the line for inserting a knife into the player backpack

		end
	end`

Since you have already accessed a player, and since every player is being looped through, you simply have to access that player’s Backpack. The Backpack is located in Player.Backpack,
So all you’d have to do is clone the knife from ServerStorage, the most secure place to keep it, and then Parent the knife into the player Backpack. Roblox and its default Inventory/Backpack system takes care of the rest. Note that for this to work properly the knife should be a Tool.

Now that I’ve laid out the steps, let’s actually go through them and add them to the code.

First we are going to want to find the knife, and since we only need to find the knife a single time, as we will make clones of it, we should find the knife outside of the loop.
So before that code, we want to find the item named “knife” in ServerStorage, which you already created a variable reference to in the first line of your script.
local Knife = ServerStorage.Knife

Finding the Knife is as simple as that.

The next step is to clone the knife, and since you need a knife for each person, you want to put this line inside the loop where I put the second comment above. This is as simple as creating a new variable for the knife and setting it as a clone of using the clone function.
local newKnife = Knife:Clone()

and the last thing to do, is to parent the knife to the player’s backpack. Since you already have the player, you just need to change the .Parent property of the newKnife yo Player.Backpack

newKnife.Parent = Player.Backpack

And that’s that.

Your end code should look like this.

` ServerStorage = game:GetService("ServerStorage")
ReplicatedStorage = game:GetService("ReplicatedStorage")
Players = game:GetService("Players")

Maps = ServerStorage:WaitForChild('Maps'):GetChildren()
Status = ReplicatedStorage:WaitForChild('Status')

while true do
	
	--Intermission
	
	local Countdown = 30 -- intermission, make this as long as you want
	
	repeat wait(1)
		Countdown = Countdown - 1
		
		Status.Value = 'Intermission : '..Countdown
	until Countdown <= 0
	
	--Choose the map.
	
	Status.Value = 'Choosing Map...'
	
	local ChosenMap = Maps[math.random(1, #Maps)]:Clone()
	local Spawns = ChosenMap:FindFirstChild('Spawns'):GetChildren()
	local RandomSpawn = Spawns[math.random(1, #Spawns)]
	
	wait(5) -- little pause, make this as long as you want
	
	ChosenMap.Parent = workspace
	Status.Value = 'Map chosen, teleporting players.'
	
	wait(2) -- little pause, make this as long as you want
	local Knife = ServerStorage.Knife
	--teleport the players
	
	for _, Player in pairs(Players:GetChildren())do
		if Player.Character and Player.Character:FindFirstChild('Humanoid') then
			Player.Character.HumanoidRootPart.CFrame = RandomSpawn.CFrame
local newKnife = Knife:Clone()
newKnife.Parent = Player.Backpack
		end
	end
	
	Countdown = 5 -- Starting Round In, make this as long as you want
	
	repeat wait(1)
		Countdown = Countdown - 1
		
		Status.Value = 'Starting Round in : '..Countdown
	until Countdown <= 0
	
	Countdown = 60 -- Game Time
	
	repeat wait(1)
		Countdown = Countdown - 1
		
		Status.Value = 'Ingame : '..Countdown
	until Countdown <= 0
	
	--Kill the players
	
	for _, Player in pairs(Players:GetChildren())do
		if Player.Character and Player.Character:FindFirstChild('Humanoid') then
			Player.Character.Humanoid:TakeDamage(2000)
		end
	end
	
	ChosenMap:Destroy()
	
	Status.Value = 'Round Ended, waiting for new game.'
	
	wait(4) -- little pause, make this as long as you want.
	
end
2 Likes