Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does my Player Respawn script keep crashing my game?

This script is intended to be used if jumping into an out of bounds area in order to prevent leaving the map, it just respawns the player but more than not it crashes my game, any reason why?

script.Parent.Touched:Connect(function(Hit)
		local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
		if Player then
			Player:LoadCharacter()
	end
end)

1 answer

✓ Accepted answer

Add a debounce. I believe it may crash because it keeps loading the character for an infinite amount of times.

local debounce = false

script.Parent.Touched:Connect(function(Hit)
        local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
        if Player then
	if debounce == false then
	debounce = true
        Player:LoadCharacter()
	wait(.01)
	debounce = false
 	   end
	end
end)

7 comments

0

If that helps at all, you can read more on debounces here: http://robloxdev.com/articles/Debounce

0

I tried adding a Debounce but it just broke the script entirely so i obviously did it wrong, Thank you i will try to better understand Debounce!

0

Is there any reason you can see to why this wouldnt work outside of studio?

0

To work as expected, a script should be used for something like this. That could be your issue if you are using a local script.

0

One more thing- LoadCharacter() would clear a players backpack and playergui so if that's not what you were hoping for you can alternatively use Player.Character.Torso.CFrame = CFrame.new(then put the new position here)

0

Yea nothing is wrong from what i can see its not a local script its in block so its just a normal script, ill just do as you said and cframe the player, thankyou for all the help :)

0

No problem, glad to help.

This discussion is preserved as it was. New answers, comments, and votes are closed.