Need help with Hamster Ball

I am trying to make a hamster ball and i want it to stay on the player all the time however with the current script you have to walk up to it and then when u respawn it doesn’t respawn with you. How do i make it stay on the player always?

-- Script --
colors = {"Bright blue","Bright red","Bright green","Bright yellow","Bright orange"}
script.Parent.BrickColor = BrickColor.new(colors[math.random(1,#colors)])

function touch(hit)
	local h = hit.Parent:FindFirstChild("Humanoid")
	if h then
		local stuff = hit.Parent:GetChildren()
		for i = 1,#stuff do
			if stuff[i].ClassName == "Hat" then
				stuff[i]:Destroy()
			end
		end
		
		game.Players:FindFirstChild(hit.Parent.Name).Character.Torso.CFrame = script.Parent.CFrame + Vector3.new(0,.5,0)
		script.Parent.Parent = hit.Parent
		local w = Instance.new("Weld")
		w.Part0 = hit.Parent.Torso
		w.Part1 = script.Parent
		w.Parent = hit.Parent.Torso
		
		while true do
			wait()
			h.Sit = true
		end
		
	end
end

script.Parent.Touched:connect(touch)

you can add a server script to connect a function to the player as soon as they enter and have it check if the player has respawned. From there you have the players directory.

game:GetService(“Players”).PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(charModel)
charModel:WaitForChild(“Humanoid”).Died:Connect(function()
print(plr.Name, “Died”)

		plr.CharacterAdded:Wait()
		
		print(plr.Name, "Spawned")
	end)
end)

end)

So for the respawn problem you could just never have them die. So check if their humanoid health is equal to zero then change it to 100 if it is. You could just parent the ball to the player.

i’m making a parkour game -__- xd

Oh then you should probably use @Myukov solution. Or you could teleport them back when they touch a part in your parkour game.

add this in the OnTouch function:

while wait() do
 h.Died:Connect(function()
--respawn hampster ball for the player.
end
end

Is there a way to just make it part of the person’s body?

if you wanted to make it part of the person’s body, put it under starter player

1 Like