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

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

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

Try doing something like

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

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