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!!!
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.
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.