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)
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)
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
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 )