User can't be kicked when String is deleted

I’ve been trying to create a simple anticheat where it kicks exploiters for not having a certain string and the issue is that it won’t kick the user when the string is deleted.

I’ve tried using “while true do” and “nil” on the script, but it still doesn’t work.

Why am I using a string?:
I’m using a string for multiple things. Class logos, characters can’t go pass through, and more other stuff. I wanted to test if an anticheat can stop it. If I need to use a value instead, it’s fine.

wait()

while true do
	if script.Parent.String == nil then
		PlayerName = script.Parent.Name
		game:GetService("Players").PlayerName:Kick("Anti Cheat: nice hacks bro")
	else
		print("ok he's not hacking thats good.")
	end
	wait(1)
end
1 Like

Is this on the server?

Anyways, playerName has to be a local variable, i.e local PlayerName = etc as it’s in a scope, Secondly from what I know the way you’re trying to do it just won’t work as PlayerName is a Variable and the script will purely look for a user called PlayerName, so overall your code should look like such:

task.wait()

while true do
	if script.Parent.String == nil then
		local PlayerName = script.Parent.Name
		game:GetService("Players")[PlayerName]:Kick("Anti Cheat: nice hacks bro")
	else
		print("ok he's not hacking thats good.")
	end
	task.wait(1)
end

This is not defined you have to let the engine know your making a new variable.

wait()

while true do
	if script.Parent.String == nil then
		PlayerName = script.Parent.Name
		game:GetService("Players"):WaitForChild(PlayerName):Kick("Anti Cheat: nice hacks bro")
	else
		print("ok he's not hacking thats good.")
	end
	wait(1)
end

Are you sure I need task.wait(1) for this?

wait() is a depreciated function and has been replaced by task.wait(), which is far safer and to my knowledge more precise.

if script.Parent.String == nil then

is the same as:

if not script.Parent.String then
local players = game:GetService("Players")

while task.wait(1) do
	if not script.Parent.String then
		PlayerName = script.Parent.Name
		players:FindFirstChild("PlayerName"):Kick("Anti Cheat: nice hacks bro")
	else
		print("ok he's not hacking thats good.")
	end
end

They can just disable the script, I wouldn’t recommend doing this as it can be bypassed quickly.
And, what is String exactly?

String is just a simple StringValue

  1. I don’t understand why you’re doing this as it can be bypassed
  2. Is this a server script or a local script?

server script, i was gonna put it a local script, but i forgot and panicked

What you’re currently checking won’t be replicated to the server since they change everything client-sided.
You should instead detect if they attempt to remove the script (it will replicate if it’s parented to their character, Player.Character.)

Here’s what a few players do:

  1. Track the client-sided anticheat with a serverscript
  2. If the localscript is removed from their character, kick them via the serverscript (since it replicates)

The downside to this is that they can just disable the localscript since that won’t replicate.
I’m not sure what you’re trying to detect, so it’ll be hard to know what you want.


I’m using a string for multiple things. Class logos, characters can’t go pass through, and more other stuff. I wanted to test if an anticheat can stop it. If I need to use a value instead, it’s fine.

I’m not sure what you mean by this, elaborate.

Basically, if String.Value == “Caveman Gibus” it will do a specific thing.

script.Parent.String must be an invalid reference then. In other words the player doesn’t have a StringValue instance named “String” parented to them. If they do and it simply hasn’t loaded yet you could try “script.Parent:WaitForChild(“String”)”, if this results in an infinite yield possible then the instance doesn’t exist.

local players = game:GetService("Players")

while task.wait(1) do
	if not script.Parent:FindFirstChild("String") then
		PlayerName = script.Parent.Name
		players:FindFirstChild("PlayerName"):Kick("Anti Cheat: nice hacks bro")
	else
		print("ok he's not hacking thats good.")
	end
end


I can’t tell what to do in this situation. Do I use events for this? I’ve tried using a Server Script and a Local Script.

This means that “players:FindFirstChild(“PlayerName”)” is returning nil, in other words you’re not getting the player object you want to kick.

what is this supposed to do what does this even mean