So, I am making an anti-hack script. But, it doesn't work. It looks like there are no typo's, and there are no errors(underlined red). But, in the output, it says:
10:59:56.639 - ServerScriptService.Anti Hack:2: attempt to index local 'plr' (a nil value)
, also, when I change the game.Workspace gravity to 0 while testing, it doesn't turn it back to 196.2. Any help is appreciated. Here's the script:
local plr = game.Players.LocalPlayer local plrc = plr.Character.Humanoid local admins = {"noob"} -- People who don't get kicked. debounce = true for i=1, #admins do if game.Players.LocalPlayer == admins[i] then debounce = false end end if not plrc.WalkSpeed == 16 or not plrc.JumpPower == 50 then local msg = Instance.new("Hint", workspace) msg.Text = "Exploiter Detected! Kicking..." plr:Kick("nice dirty hacks lol") wait(5) msg:Destroy() end if workspace.Gravity == not 196.2 then workspace.Gravity = 196.2 end
You're trying to access the local player from a serverscript.
This isn't possible, there are a few ways to get players though (playeradded, etc)
This doesn't mean you can make it client because :Kick() would not work then
To fix it I recommend using for i,v in pairs like this
local admins = {"noob"} -- People who don't get kicked. debounce = true for i=1, #admins do for index, plr in pairs(game.Players:GetChildren()) do if plr == admins[i] then debounce = false end end end while wait(1) do for index, plr in pairs(game.Players:GetPlayers()) do local char = plr.Character or plr.CharacterAdded:wait() local plrc = char:WaitForChild('Humanoid') if not plrc.WalkSpeed == 16 or not plrc.JumpPower == 50 then local msg = Instance.new("Hint", workspace) msg.Text = "Exploiter Detected! Kicking..." plr:Kick("nice dirty hacks lol") wait(5) msg:Destroy() end end if workspace.Gravity == not 196.2 then workspace.Gravity = 196.2 end end
If I made a mistake or you have a question, just ask :)