I want that after you joined the game the player gets resetted.
But if I use this code, the player keeps getting resetted because of the CharacterAdded function
It’s because your constantly removing the characters Head upon creation. I suggest doing something like this.
game.Players.PlayerAdded:Connect(function(Player)
game.Players.RespawnTime = 0.2
local Character = Player.CharacterAdded:Wait()
Character:WaitForChild("Head"):Destroy()
end)
Instead of adding a wait(5), you could try adding CharacterAdded:Wait() so the script only runs until the character is fully incorporated into the game. I think @Arthur_Grandwell already used this in his script but I’d like to remind you still of this function.
if not player.Character then player.CharacterAdded:Wait() end
game.Players.PlayerAdded:Connect(function(Player)
game.Players.RespawnTime = 0.2
local Character = Player.CharacterAdded:Wait()
wait(10)
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid:TakeDamage(Humanoid.MaxHealth)
end)
You might as well change to respawn time manually in the explorer and you can switch the wait with task.wait if you want to wait a few seconds after the char spawns
If you want to do this, you could try using task.wait() instead as wait() pauses your thread and task.wait() continues normally. I believe wait() also has some small performance issues.
(Here’s a link with more informations about task.wait())
task.wait() still yields the thread, it does the same as wait() but with the new task scheduler.
You could use task.delay() instead as that takes a function and doesn’t yield the current thread.
game.Players.PlayerAdded:Connect(function(Player)
game.Players.RespawnTime = 0.2
local Character = Player.CharacterAdded:Wait()
task.wait(20)
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid:TakeDamage(Humanoid.MaxHealth)
end)