Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does my Player Respawn script keep crashing my game?

Asked by
PastDays 108
5 years ago
Edited 5 years ago

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

Log in to vote
0
Answered by
Voy1980 111
5 years ago

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)
0
If that helps at all, you can read more on debounces here: http://robloxdev.com/articles/Debounce Voy1980 111 — 5y
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! PastDays 108 — 5y
0
Is there any reason you can see to why this wouldnt work outside of studio? PastDays 108 — 5y
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. Voy1980 111 — 5y
View all comments (3 more)
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) Voy1980 111 — 5y
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 :) PastDays 108 — 5y
0
No problem, glad to help. Voy1980 111 — 5y
Ad

Answer this question