Creating a script that crashes the player on touch

I am trying to create a script that crashes the player who touched the part using a on touch function. I’ve tried doing a while true do function but it seems to make the whole server crash instead of affecting the player who touched the part.

This is for players who try to glitch outside the given environment or try to exploit the game and go into places that they are not supposed to go to.

3 Likes

Could you not just kick them?

local part = script.Parent
part.Touched:Connect(function(hitPart)
    if hitPart.Parent:FindFirstChild("Humanoid") then
        local character = hitPart.Parent
        local player = game.Players:GetPlayerFromCharacter(character)
        player:Kick("You have left the playable bounds")
    end
end)

or you could even just teleport them back to the spawn area.

3 Likes

Its better to kick the player rather then crashing them. But the best way might be to activate a local script inside the player that has a while true do function.

3 Likes

while wait(0) do
end

while true do
end

One of those will do it, or both.

1 Like

Kicking is a way to disturb the player but instead of kicking I want to give the exploiter a hard time. I’ve thought about kicking before but they always come back through an alt… Crashing the exploiter would be very annoying for the exploiter which is the reason I was trying to do a crash script

Either way, the player is only temporarily removed for a short period of time and are always able to join back on the same account, let alone an alt. Both do the exact same thing, one is just a given method easier to execute and doesn’t rely on (while true do end) crashing clients.

There is no way to permanently remove of exploiters. You can try banning them using datastores, but as you say, they will just create an alt account. Instead, try fixing areas within your game that are exploitable. Client-side attempts to “remove” exploiters will never work as you’d expect. “Crashing” or kicking is only a temporary measure that will stop only the weakest of exploiters.

1 Like

How would I execute this if the player touches a part (I’m really really new to scripting and don’t know how to script this so I’m very sorry for my lack of knowledge)

2 Likes

Wait has a minimum. Putting 0 as the wait time would not crash a game, it’d use the default time. It’s in times like this where the validity of avoiding the While-Wait-Do idiom is all the more apparent.

That being said - shouldn’t be crashing the player at all for any reason.

5 Likes

Instead of using while wait function should I just use while true do function to crash the player?

1 Like

Exploiters can’t in fact “delete the source” of a LocalScript. And even if they could, 99% of them would just use this single line of code to render all your infinite loops useless:

game:GetService("ScriptContext"):SetTimeout(1)

That being said, they can do other things to prevent the crash, which your code cannot stop.
Therefor OP should not fully rely on a crash (and imo not implement it in the first place, just kick them instead).

3 Likes

exploiters can just disable the script instead of removing it

1 Like