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
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
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
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
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:
Track the client-sided anticheat with a serverscript
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.
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