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

Does anyone know why it says all the time "attempt to index a nil value"?

Asked by 6 years ago

Hello, so i'm trying to load value from ReplicatedStorage into a normal leaderboard, but it just keep saying "ServerScriptService.LinkedLeaderboard:138: attempt to index a nil value".

Problem is in these lines:(Original lines)

local PlayerStats = game.ReplicatedStorage.PlayerStorage.Store:FindFirstChild(newPlayer.Name).PointsStorage
        if PlayerStats ~= nil then
            if cash then
                local Short = Settings.LeaderboardSettings.ShowShortCurrency
                PlayerStats.Changed:connect(function()
                    if (Short) then
                        cash.Value = Settings:ConvertShort(PlayerStats.Value)
                    else
                        cash.Value = Settings:ConvertComma(PlayerStats.Value)
                    end
                end)
            end
        end

Even i tried to separate PointsStorage from it and add new line with it.

Here is changed a bit script:

local PlayerStats = game.ReplicatedStorage.PlayerStorage.Store:FindFirstChild(newPlayer.Name)
        if PlayerStats ~= nil then
local plrStats = PlayerStats:FindFirstChild("PointsStorage")
if plrStats ~= nil then
            if cash then
                local Short = Settings.LeaderboardSettings.ShowShortCurrency
                plrStats.Changed:connect(function()
                    if (Short) then
                        cash.Value = Settings:ConvertShort(plrStats.Value)
                    else
                        cash.Value = Settings:ConvertComma(plrStats.Value)
                    end
                end)
                end
            end
        end

Error dissapeared, but script still don't work..

0
Can you give us the full error message, or tell us which of the above lines is line 138? WillieTehWierdo200 966 — 6y
0
Line 138 is the first line(01) in this part of the script which i typed here. I can paste here full script, but it's long script. karolus1 8 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

I think I see a problem. Scripts mostly load in first then other objects, and it will immediately execute the code within the script. Instead of game.ReplicatedStorage.PlayerStorage you should use the :WaitForChild("object name here"), that why the script will wait for the object to be there.

Example:

local RP = game:GetService("ReplicatedStorage")

RP:WaitForChild("PlayerStorage"):WaitForChild("Store") --and such

I hope this helped but if this somehow did not work, I do not know what to do after that.

0
Really? I thought about it for an hour.. Anyway thanks, works fine now :D Still have to learn a lot about scripting ^^ karolus1 8 — 6y
0
No problem, and good luck on your scripting journey! :D CounterBoy123 53 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

I'm noticing that cash either wasnt made or isnt visible. Please, if any if statements dont work, you must test and fix those immediately. I recommend using print statements

0
Well, it's not full script, it's just part with error. Script is longer, but "cash" was made. I tried with prints statements and it don't show me them, so there's problem with this part. karolus1 8 — 6y

Answer this question