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

Could you help me with this ModuleScript bug?

Asked by
novipak 70
10 years ago

Okay, I have been experimenting with ModuleScripts, and I've gotten this bug and I'm not really sure as to how to fix it. I'm attempting to stop speed hackers in my game with this.

ModuleScript(in Workspace):

local g_logic = {}
walkspeed_allowed = false
allowed_walkspeeds = {16}
function g_logic.check_walkspeeds(ws)
    for i,v in pairs(allowed_walkspeeds) do
        if ws == v then
            walkspeed_allowed = true
        end
    end
    if not walkspeed_allowed then
        game.Players.LocalPlayer:Kick()
    end
    walkspeed_allowed = false
end
return g_logic

LocalScript(in StarterGui[this probably isn't the right place for it, but it runs in here.]):

local g_logic = require(game.Workspace.game_logic)
local player = game.Players.LocalPlayer
player.CharacterAdded:connect(function()
    repeat wait() until player.Character.Humanoid
    hum = player.Character.Humanoid
    hum.Changed:connect(function(WalkSpeed)
        g_logic.check_walkspeed(hum.WalkSpeed)
    end)
end)

The error I got was:

Players.Player1.PlayerGui.anti_speed_2:7: attempt to call field 'check_walkspeed' (a nil value)

Thanks for helping.

1 answer

Log in to vote
1
Answered by
DataStore 530 Moderation Voter
10 years ago

The function you've created in the ModuleScript is 'called' check_walkspeeds, not check_walkspeed. You attempt to use the latter in the LocalScript you've given us.

Just change the following

g_logic.check_walkspeed(hum.WalkSpeed)

To,

g_logic.check_walkspeeds(hum.WalkSpeed)
0
Oh god. I feel silly now. It works! Thank you. novipak 70 — 10y
Ad

Answer this question