oh maybe try to move while loop outside the PlayerAdded function?. and humanoid.Touched:Connect(damage()) you don’t need to loop this. it will automatically fired when something touching.
Note: humanoid.Touched:Connect(damage()) humanoid can’t be touched, maybe try use “humaoidrootpart”
if your mob is going to be moving towards the player, then you’re referencing nothing? you seem to be just referencing the player that joins in every time. just set the script as a parent to your mob instead of serverscriptservice.
i don’t think it’s going to work if the function will activate with a player joining, i highly recommend you just make a loop, and get the closest player to you by using .Magnitude and then the closest player will make the mob follow them maybe?
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.