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

Why am I getting 'Attempt to concatenate field 'UserId' (a nil value)'?

Asked by 5 years ago

When I try to change player data using a module script, it gives me an error... Any help would be nice.

Error: 23:09:45.463 - ReplicatedStorage.ModuleScript:14: attempt to concatenate field 'UserId' (a nil value)

ModuleScript:

function PlayerStatManager:ChangeStat(player, statName, value)
    local playerUserId = "Player_" .. player.UserId
    assert(typeof(sessionData[playerUserId][statName]) == typeof(value), "ChangeStat error: types do not match")
    if typeof(sessionData[playerUserId][statName]) == "number" then
        sessionData[playerUserId][statName] = sessionData[playerUserId][statName] + value
    else
        sessionData[playerUserId][statName] = value
    end
end

Script:

script.Parent.MouseClick:Connect(function(plr)
    print(plr)
    local module = require(game.ReplicatedStorage.ModuleScript)
    module.ChangeStat(plr, "Money", 100)
end)

P.S: I'm really new to using module scripts...

0
short answer, change the period on line 4 of your script to a colon theking48989987 2147 — 5y
0
Thanks. Now im getting a new error. On like 3 of module script. kittonlover101 201 — 5y

Answer this question