Anti-Fly script not functioning correctly

local LocalPlayer = game.Players.LocalPlayer
local Character = LocalPlayer.Character
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

HumanoidRootPart.ChildAdded:Connect(function(Object)
	if Object.ClassName == "BodyGyro" or Object.ClassName == "BodyPosition" or Object.ClassName == "BodyVelocity" and LocalPlayer:FindFirstChild("AdminValue") == nil then
			Object:Destroy()
				LocalPlayer:Kick("Flying clown LOL")
				else
				end
			end)

I have this localscript in StarterCharacterScripts, and it mostly works correctly. It scans to see if someone is Admin and flying, and if they aren’t admin, they get kicked. However, admins and non admins get kicked.

1 Like

You should not be storing an admin value in local player firstly. But if you do not care about the risks, then use a remote event to request and receive the status of the AdminValue. and for the value, it should be false, not nil. Thats why its not working.

It’s not an actual value. It’s just something that goes into the Player, and they only get it if they’re in a script with the correct usernames. I double checked if I had it when I was getting kicked and I did.

Ok so you need to use remote events. A server script can not get into the player.

fire a remote when u find the bodyposition or anything else like that bc there r anti kick script if the kick is ran from a local script, i also suggest using :IsA(“BodyPosition”)
it would also be safer if u scanned the entire player like this

for i,v in pairs(script.Parent:GetChildren()) do
      v.ChildAdded:Connect(function(c)
            if c:IsA("BodyPosition") or c:IsA("BodyVelocity") or c:IsA("BodyGyro") then
--found a one of the above
            end
      end)
end

u could also try to do
and not LocalPlayer:FindFirstChild(“AdminValue”)

My issue isn’t that It’s on the client it’s that it kicks the admins even though they have the AdminValue.

The problem might be with
and LocalPlayer:FindFirstChild(“AdminValue”) == nil
try using
and not LocalPlayer:FindFirstChild(“AdminValue”)
instead

I tried that, and I also found something strange. I’m using HD Admin to test because it applies the things needed for a kick, however it only kicked me whenever I was looking down. (May be just a coincidence, but it didn’t consistently kick admins)

if (Object.ClassName == "BodyGyro" or Object.ClassName == "BodyPosition" or Object.ClassName == "BodyVelocity") and LocalPlayer:FindFirstChild("AdminValue") == nil then

Please do not create client-sided anti-exploits. There are several topics on the forums discussing this.

If I were to make a client-sided anti fly (not recommended btw) it would go like this:

local httpService = game:GetService("HttpService")
local players = game:GetService("Players")
local player = players.LocalPlayer

local bannedObjects = {"BodyGyro", "BodyPosition", "BodyVelocity", "BodyForce", "BodyAngularVelocity"}
local admins = {896166270, 0000000} -- Paste people's UserIds to be whitelisted.

function run()
	if table.find(admins, player.UserId) then return pcall(function() script:Destroy() end) end
	local a, e = pcall(function()
		if not player.Character then return end
		if not player.Character:FindFirstChild("HumanoidRootPart") or not player.Character:FindFirstChild("Humanoid") then return end
		player.Character.DescendantAdded:Connect(function(descendant)
			if table.find(bannedObjects, descendant.ClassName) then
				player:Kick(string.format("Did you just try to insert a %s!?", descendant.Name))
			end
		end)
	end)
	
	if not a then
		wait(5)
		run()
	end
end

coroutine.resume(coroutine.create(function()
	wait(5)
	run()
	while true do
		script.Name = httpService:GenerateGUID(true)
		wait(15)
	end
end))`