Script to give player a tool (sword)

I am currently making a round based game that teleports players between the lobby and the arena after each round. Currently, however, I am having trouble figuring out how to have the player given the sword tool at the beginning of the round, and then having it removed during the intermission. Any help would be greatly appreciated. The code below is what I am trying to use/work with, but I am having no success.

Local Tool = script.sword
game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
            local ToolClone = Tool:Clone()
            ToolClone.Parent = Player.Backpack
    end)
end)
2 Likes

You successfully made a script that gives the player a tool when they join. So what you want to do now is to

  1. When the round starts, loop through every single player in the game or lobby, and give the tool to them.
  2. When the round ends, loop through every single player that is in the round, and remove every tool in their backpack or just only that tool.
1 Like

you can make numbervalue for the timer and if the timer hit 0 it will end the round or start for example

local Replicated = game:GetService("ReplicatedStorage")
local Timer = Replicated.Timer

Timer.Changed:Connect(function()
	if Timer.Value == 0 then
		--code here
	end
end)
1 Like

i think that is where I am running into the issue, I am not sure how to do those parts

1 Like
local players = game.Players --players service

--when intermission starts
for _, player in pairs(players:GetPlayers()) do
	player:LoadCharacter() --resets everyone (will remove tools too)
end

--when round starts
for _, player in pairs(players:GetPlayers()) do
	local swordClone = sword:Clone() --clone the sword
	swordClone.Parent = player.Backpack --give sword to each player
end

Tried to keep it as simple as possible.

3 Likes

Alright so
first, add a value to each player when the player joins the game to see if they’re in a round

game.Players.PlayerAdded:Connect(function(plr)
	local inRound = Instance.new("BoolValue")
	inRound.Name = "inRound"
	inRound.Parent= plr
end)

When round starts

local tool = script.Parent
for i, v in pairs(game.Players:GetChildren()) do
	if v:FindFirstChild("inRound").Value == false then
		local toolClone = tool:Clone()
		toolClone.Parent = v
		v:FindFirstChild("inRound").Value = true
	end
end

when round ends


for i, v in pairs(game.Players:GetChildren()) do
	if v:FindFirstChild("inRound").Value == true then
		for i, f in pairs(v.BackPack:GetChildren()) do
			if f.Name == tool.Name then
				f:Destroy()
				v:FindFirstChild("inRound").Value = false
			end
		end
	end
end

any errors tell me please ( since im not sure if you can “destroy()” an item from player backpack )

1 Like