Ping pong event with InvokeClient breaking when localscript destroyed

Hello,

I’m trying a ping-pong script, so that I can check if my client anti-cheat is disabled or not. When disabled, it errors with “Script that implemented this callback has been destroyed while calling async callback”. How do I prevent it from erroring and just kicks the player when it’s destroyed instead?

-- Server
local Remotes = game:GetService("ReplicatedStorage"):WaitForChild("Remotes");

game:GetService("Players").PlayerAdded:Connect(function(Player)	
	local PingPong = coroutine.create(function()
		while true do
			wait(5);
			
			local Ping = Remotes.PingPongEvent:InvokeClient(Player);
			
			if not Ping then
				Player:Kick("Ping-pong event broken.");
			end;
		end;
	end);

	coroutine.resume(PingPong);
end);
-- Client
local Remotes = game:GetService("ReplicatedStorage"):WaitForChild("Remotes");

Remotes.PingPongEvent.OnClientInvoke = function()
	return true;
end;
1 Like

What if you wrapped the serverside code in a pcall? So then if the local script is deleted and it errors the pcall will detect the error and instead of stopping the code it’ll run the error to kick the player.

1 Like