Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

game.Players.LocalPlayer is nil, also won't change the game.Workspace gravity. How to fix?

Asked by 5 years ago
Edited 5 years ago

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
0
this script wouldn't work if filtering enabled was on, because walkspeed would still show as 16. i think you should detect the velocity of the torso or something like that. this doesn't mean that you shouldn't use fe, i encourage you to use it since the game will be way more secure brokenVectors 525 — 5y

1 answer

Log in to vote
2
Answered by 5 years ago

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 :)

0
You don't have to say "not" all the time. Just say ~= and it's faster. User#19524 175 — 5y
1
I copied his script and fixed it lol, I didn't rewrite it completely, but you're right User#20388 0 — 5y
Ad

Answer this question