Prevent LocalScripts from executing after kick

Hi!

My case:
I’m kicking a player, so the player will get “invisble”/deleted from the server. But for the player him/her-self the screen is just blurred and the kick gui pops up (the default roblox kick gui). But if you look closer, you can see, that the character is still executing the “breathing” animation. (So that basically shows, that the LocalScript “Animate” inside of the character is still executing.) Finally my real problem: I got a script, where the client keeps on firing a remote event to the server, and if the server doesnt respond, the LocalScript will basically change the kick message…

https://drive.google.com/file/d/1NoZUKp_g9GcH5JM54EAcCyBvrqgDRgs2/view?usp=sharing

Question:
How do I stop LocalScripts from executing after the player was kicked?

for i, v in pairs(player:GetDescendants()) do
  if v:IsA("LocalScript") then
    v.Disabled = true
    v:Destroy()
  end
end
1 Like

Are you able to explain, or can’t you? lol

Run the code before the player is kicked (I think)

It loops through everything in the player’s instance detects if its a local script and disables then deletes it

Error: He said the “Animate” script. That’s inside players’ character, not the player itself. Cycle through the character too.

That would only partially work.
Script threads that have been running will still run, even after disabling and destroying the script.

Calling :Destroy() yields all threads and breaks all connections I think

Also do player.Character:Destroy() or just player:Destroy() lol

No it doesn’t, it just permanently parents the script to nil and prevents future threads from running.

unless i read the documentary incorrectly

Maybe use coroutines and yield the thread (but that would modify the animate script, so proceed with caution)