So basically I am making a round based game and in a certain game mode I want it so that when the player dies he respawns at the start of the map(I already figured out how to do that) and with a sword cloned into the character, so basically he spawns already equipping the sword.
Here’s the code that’s not working:
for _, Player in pairs(plrs)do
if Player then
local char = Player.Character
if char then
local humanoid = char:FindFirstChild("Humanoid")
if char:FindFirstChild("Humanoid").Health == 0 then
if Chosengame.Name == "Battle Tiles" then
Player.Team = Playingteam
Player.CharacterAdded:Connect(function()
local swordvalue = Player.ToolStats.Sword.Value
wait(0.5)
local plrsword = ReplicatedStorage.BuyableItems:FindFirstChild(swordvalue)
local swordclone = plrsword:Clone()
swordclone.Parent = humanoid.Parent
end)
else
Player.Team = Lobbyteam
local toolstats = Player.ToolStats.Sword.Value
if Player.Backpack:FindFirstChild(toolstats) then
local plrsword = Player.Backpack:FindFirstChild(toolstats)
plrsword:Destroy()
elseif Player.Character:FindFirstChild(toolstats) then
local charsword = Player.Character:FindFirstChild(toolstats)
charsword:Destroy()
end
end
end
end
end
end
Ok so I did this and for some reason it put me in the lobby team and sent me back to the lobby with a thousand swords equipped rip
local humanoid = char:FindFirstChild("Humanoid")
humanoid.Died:Connect(function(hum)
if Chosengame.Name == "Battle Tiles" then
Player.Team = Playingteam
wait(0.5)
local swordvalue = Player:WaitForChild("ToolStats"):WaitForChild("Sword").Value
local plrsword = ReplicatedStorage.BuyableItems:FindFirstChild(swordvalue)
local swordclone = plrsword:Clone()
swordclone.Parent = humanoid.Parent
else
Player.Team = Lobbyteam
local toolstats = Player.ToolStats.Sword.Value
if Player.Backpack:FindFirstChild(toolstats) then
local plrsword = Player.Backpack:FindFirstChild(toolstats)
plrsword:Destroy()
elseif Player.Character:FindFirstChild(toolstats) then
local charsword = Player.Character:FindFirstChild(toolstats)
charsword:Destroy()
end
end
end)
local Debounce = false
humanoid.Died:Connect(function(hum)
if Debounce then return end
Debounce = true
if Chosengame.Name == "Battle Tiles" then
Player.Team = Playingteam
wait(0.5)
local swordvalue = Player:WaitForChild("ToolStats"):WaitForChild("Sword").Value
local plrsword = ReplicatedStorage.BuyableItems:FindFirstChild(swordvalue)
local swordclone = plrsword:Clone()
swordclone.Parent = humanoid.Parent
else
Player.Team = Lobbyteam
local toolstats = Player.ToolStats.Sword.Value
if Player.Backpack:FindFirstChild(toolstats) then
local plrsword = Player.Backpack:FindFirstChild(toolstats)
plrsword:Destroy()
elseif Player.Character:FindFirstChild(toolstats) then
local charsword = Player.Character:FindFirstChild(toolstats)
charsword:Destroy()
end
end
task.wait(1)
Debounce = false
end)