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

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

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..

2 comments

0

Can you give us the full error message, or tell us which of the above lines is line 138?

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.

2 answers

✓ Accepted answer

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.

2 comments

0

Really? I thought about it for an hour.. Anyway thanks, works fine now :D Still have to learn a lot about scripting ^^

0

No problem, and good luck on your scripting journey! :D

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

1 comment

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.

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