Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Attempt to call method 'ChangeStat' (a nil value)? Plz help me:/

Okay I very don't understand? I want have access has my ModuleScript in my LocalScript. So I have create a RemoteFunction but I received this error...

Error: Attempt to call method 'ChangeStat' (a nil value)

ModuleScript Position = ServerStorage

(ExpSystem) LocalScript:

--local PlayerStatManager = require(game.ServerStorage.PlayerStatManager)
local Func = workspace.AccessServer:WaitForChild('AccessModuleScript')
local PlayerStatManager = Func:InvokeServer()

local expression = player.leaderstats.Level.Value * 2 * math.floor(500 * (3 ^ (3 / 15.47452)))

local player = game.Players.LocalPlayer

player.leaderstats.Exp.Changed:connect(function()
	if player.leaderstats.Exp.Value >= expression then
		PlayerStatManager:ChangeStat(player, 'Level', 1)
	end
end)

(RequireInfo) Script:

local Func = workspace.AccessServer:WaitForChild("AccessModuleScript")

function Func.OnServerInvoke()
	local PlayerStatManager = require(game.ServerStorage.PlayerStatManager)
	return PlayerStatManager
end

2 comments

0

Whatever code that the Module returns doesn't seem to consist of a ChangeStat function.

0

But in the module there is a function named 'ChangeStat'?

1 answer

At the bottom

local Func = workspace.AccessServer:WaitForChild("AccessModuleScript")

function Func.OnServerInvoke()
    local PlayerStatManager = require(game.ServerStorage.PlayerStatManager)
    return PlayerStatManager
end

Well, I am not experienced with RemoteFunctions and bindable functions but let's try this at the bottom

local Func = workspace.AccessServer:WaitForChild("AccessModuleScript")

local function ChangeStat()--Change "ChangeStat" too what you want
	local PlayerStatManager = require(game.ServerStorage.PlayerStatManager)
        return PlayerStatManager
end
--remember: RemoteFunction uses callback
Func.OnServerInvoke() = ChangeStat

try that

V--may you read this please--V Well i read this from here from the lua roblox api:

"Note that binding a function to OnServerInvoke is done with the assignment operator =, and not with an event. That is because OnServerInvoke is a callback and expects a function to be assigned to it. When the RemoteFunction is invoked, it will execute the function that was assigned to the onInvoke function."

2 comments

0

ServerScriptService.RequireInfo:8: unexpected symbol near '='

0

_> Let me try, <5 years later> aha, i forgot an letter, solved! Jk, but i am going to take a look at it

This discussion is preserved as it was. New answers, comments, and votes are closed.