Problem With Respawning with Tools

Hey! I made a script that should make you respawn with your tools whenever you die. The problem is that if you have that tool equiped, then it doesn’t respawn with you. The script is also designed to fix that problem, but it still doesn’t work for some reason.

game.Players.PlayerAdded:Connect(function(plr)
	
	local items = Instance.new("Folder", plr)
	items.Name = "Items"
	
	plr.CharacterAdded:Connect(function(char)
		
		local hum = char:FindFirstChild("Humanoid")
		for i, v in pairs(items:GetChildren()) do
			v.Parent = plr.Backpack
		end
		
		hum.HealthChanged:Connect(function()
			
			if hum.Health <= 0 then
				if char:FindFirstChildOfClass("Tool") then
					char:FindFirstChildOfClass("Tool").Parent = items
				end
				for i, v in pairs(plr.Backpack:GetChildren()) do
					v.Parent = items
				end
			end
		end)
	end)
end)

If you have an idea on what might be going on, or if you have a different solution, just let me know! Thanks!

3 Likes

Try to clone it, amybe that should help.

2 Likes

not sure why you’re creating the items as the player joins the game, i would just keep them somewhere else and clone them in when the player joins.

Also, instead of humanoid.HealthChanged you can use humanoid.Died event so you don’t have to check if their health is 0

Also, instead of creating a folder and putting items there what you can do is clone the items into Player.StarterGear, which will automatically clone its contents into the players backpack when they respawn.
You can learn more about it here

2 Likes

It appears as if you are missunderstanding the problem. These are gamepass items, I have knowledge of StarterGear and I wouldn’t have had this problem if this wasn’t based on gamepasses. I can try cloning it though. Also, the items folder doesn’t have all the gears in it since it is a new instance. There should only be instances in it whenever transfering back and forth between the backpack and itself when the player dies.

1 Like

why are you moving them back and forth instead of just letting them get destroyed and cloning new ones when the player respawns?

1 Like

Im not sure how I should script that… could you show an example?

well the simplest way to do it would be to check for gamepasses when a player joins and then just insert the gamepass gear into their StarterGear, and then the gear would clone into their backpack when they respawn(you would have to manually insert it into their backpack when they join for the first time tho because their character would spawn before the code has a chance to run)
so you would have minimum coding to do
1.on player added check what gamepasses they have
2. put the corresponding gamepass gear into their StarterGear
3. manually clone the gear into their backpack on joining because it won’t clone the first time

and that’s it unless i am forgetting something. Sorry I can’t write you a code example right now but if you are still having trouble i will write you an example later

hey sorry for wait || would i use a local script because i dont think there is a startergear for each individual player unless i didn’t know about that

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.