How do I improve this little script?

The wait(10) is unnecessary, as you are already using CharacterAdded.

you should mark @Poneware as the solution and use his code

Ik, but I want that it only happens 5 or 10 secs after the char spawned

Just do

game.Players.PlayerAdded:Connect(function(Player)
	game.Players.RespawnTime = 0.2
Player.CharacterAdded:wait()
	wait(5)
	Player:LoadCharacter()
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

I see.

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.

1 Like
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)

Like that?

game.Players.PlayerAdded:Connect(function(Player)
	game.Players.RespawnTime = 0.2
	Player.CharacterAdded:Wait()
	task.delay(20, function()
		Player:LoadCharacter()
	end)
end)

Edit: Yes load character does reset the character

Edit 2: did you wait 20 seconds, because it works fine for me

Does LoadCharacter reset the character?

I think it works in client

local Player = game.Players.LocalPlayer
repeat
	wait()
until
Player.Character
Player.Character.Head:Destroy()

Sadly, this doesn’t work. I didn’t get resetted

Weird.

Also, I wouldn’t set the RespawnTime so low, as it has tendency to break my avatar when I set it below 2-1.

It works fine for me maybe try it again and wait 20-30 seconds?

I did. It doesn’t work for me.

Did you put it in a server script?

Yes. In workspace. Shouldnt be a problem.

Are you sure, because this work fine for me

game.Players.PlayerAdded:Connect(function(Player)
	task.delay(20, function()
		Player:LoadCharacter()
	end)
end)

Can you load the char multiple times because I already do it on join in another script but I want it to do after 20 secs again in a different script.

no. doing it on join will break the character or do nothing. just do it in once