I want to clone a sword into the character when he spawns

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
2 Likes

You have to clone it into the character model, not into the humanoid
Oh sorry, i just saw it, i misunderstanded

1 Like

I cloned it into humanoid.Parent to make sure I was getting the right humanoid, as for some reason once it spawned into the other character

1 Like

So it gives the sword to another player?

1 Like

no now it doesn’t give the sword to anybody

1 Like

Because there is no loop, try connecting a function to the humanoid like Humanoid.Died:Connect(function…

1 Like

Send the whole script and ill edit it if u did not understand

1 Like

ima try that now real quick ill tell you if it doesnt work

1 Like

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

Add a debounce variable for 1 second

1 Like

so I just do wait(1) after the humanoid.Died function?

1 Like

Like this:

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)

İ cant format it i am in mobile

1 Like

Does it work?

strong text
strong text

1 Like

sorry I went to eat dinner, ima test it out now

1 Like

so basically when I die a thousand swords get cloned into my character and then when I respawn they’re all gone

1 Like

Add a characteradded after humanoid.died

1 Like

sorry I had to go rip, Ima test that out now