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

if player leaves while they are using a long ability then the script stops running?

Asked by 2 years ago
Edited 2 years ago

So I have multiple attacks in my game (such as grab attacks that last multiple seconds), and if a player leaves while using one of these attacks on another player, or while someone is using one of them on the player, then the script will fail to find the player or their character and the script will stop running because of this, meaning that the other player in the attack will most likely have their camera stuck in a tweened position, or their rootpart will permanently be anchored. What is a way I can go about making it so that the script will continue to run even if the game can't find the player? I know of pcalls but wrapping every little part of the attacks in a pcall function will be extremely repetitive and I'm wondering if there's any better way of fixing this. (By the way none of these attacks use WaitForChild() )

1 answer

Log in to vote
0
Answered by 2 years ago

Try doing something like

--insert code
if player.Character ~= nil then
    --continue attack
else
    --stop attack and unanchor stuff
end
Ad

Answer this question