Why is this ERRORING?

I am working on an anti-cheat script, and this keeps erroring! I looked at the if statement and it’s completely fine!

local client = game:GetService("Players").LocalPlayer
local function flash()
	if client.PlayerGui == true then -- Erroring and breaking the script if PlayerGui was deleted.
		if client.PlayerGui.Caught == true then
			client.PlayerGui.Caught.ShiftColor.Visible = true
			wait(1)
			for i = 255, 0,-10 do
				wait(0.00000001)
				client.PlayerGui.Caught.ShiftColor.BackgroundColor3 = Color3.fromRGB(i, 0, 0)
			end
			wait(1)
		end
	end
	client:Kick("ENGINE Anti-Exploit has detected you.")
end

What do I do? I was working on trying to fix this for like 5 hours straight!!!

Try replace if client.PlayerGui == true then with if client.PlayerGui then

It did the error again.image

the problem is this is a local script

Exploiters execute scripts on a localscript side. A server script cant detect this

Are you trying to detect if the player has deleted their own player gui?
I don’t really understand what would the point be? This only affects the exploiter and not other clients.

Yep, the entire anti-cheat breaks if the player deletes their playergui. So I want to make that sort of optional for the script

Maybe client:FindFirstChild("PlayerGui") or client:WaitForChild("PlayerGui) ?

Maybe if not client.PlayerGui then ?

Thank you so much! It worked! I got no errors.

My first solution!! :grinning:

1 Like

I understood you are trying to make an anti-cheat script, but this one, unfortunately, won’t work properly. Yes, I made it italic because there is a chance to let it work. But if you want to get more information and if you still think about that, let’s start.

Running a local script inside the client will make it open to the customer, exploiters. So this wouldn’t be a good idea.

I guess you should run it inside a server script and ServerScriptService, which is protected from the client.


Before I give you the script, I’ll give you a bit of advice.

wait function couldn’t wait for that number. It waits for approximately 1/30 of a second. Using TweenService is a better way to do that.

And if you want to kick a player from the client, don’t do that. It is better if you kick from a server-side script.

-- Server script

local ReplicatedStorage = game:GetService("ReplicatedStorage")

game:GetService("Players").PlayerAdded:Connect(function(player)
    player:WaitForChild("PlayerGui")

    if player:FindFirstChild("PlayerGui") then
	    ReplicatedStorage.Tutorial:FireClient(player)
	end
end)

ReplicatedStorage.Tutorial.OnServerEvent:Connect(function(plr)
    plr:Kick()
end)

-- Local script
    
local player = game:GetService("Players").LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local ShiftColor = player.PlayerGui.Caught:FindFirstChild("ShiftColor")

local info = TweenInfo.new(
    10,
    Enum.EasingStyle.Linear,
    Enum.EasingDirection.Out,
    0,
    false
)

ReplicatedStorage.Tutorial.OnClientEvent:Connect(function()
    ShiftColor.Visible = true
    local play = TweenService:Create(ShiftColor, info, {BackgroundColor3 = Color3.fromRGB(0, 0, 0)})

    play:Play()

    play.Completed:Connect(function()
        ReplicatedStorage.Tutorial:FireServer()
    end)
end)

If you provide it with a RemoteEvent, you can communicate between the client and the server. This is why I used it here, because of the risk of the local script being deleted and kicking the player from their client.

Can’t the remote be fired by the exploiter, allowing them to kick other players?

This parameter is only used for those who fired from their client, so this will be their fault.