See if this code works:
game.Players.PlayerAdded:Connect(function(player)
local humanoid = script.Parent.Humanoid
local function damage(hit)
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Humanoid.Health -=3
end
end
repeat wait() until player.Character
humanoid.Touched:Connect(damage)
while wait() do
humanoid:MoveTo(player.Character.HumanoidRootPart.Position)
end
end)
I’ve added a repeat wait()
to make sure that the Player’s Character is spawned, and I’ve changed while true
to while wait()
as to not have the script crash.