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

Attempt to index a nil Value?

whenever i test this gamepass is tells me attempt to index nil with a value.like this worked for other things why doesent it work on this.

local id = 10391218
local stats = game.ServerScriptService:WaitForChild("LeaderStats"):FindFirstChild("leaderstats")
local Pmoney = game.ServerScriptService:WaitForChild("LeaderStats"):FindFirstChild("Cash")
local Pmulti = game.ServerScriptService:WaitForChild("LeaderStats"):FindFirstChild("Multi")
local Preb = game.ServerScriptService:WaitForChild("LeaderStats"):FindFirstChild("Rebirths")
game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(plr,ido,purchased)
if purchased and id == ido then
Pmulti.Value = Pmulti.Value + 1000000 --problem
end
end)

sorry if this is very messy i tried to make it simple but it didn't work or maybe it did.

4 comments

0

i messed up on the script part

0

Please put this in a code block

0

ok yeah sorry i did that but didnt work

0

There finally it worked in a code block

2 answers

Maybe use ("LeaderStats"):WaitForChild(variableName) so it will yield until the object is loaded. If this doesn't work then please click on the error message in the output and tell us which line the error is from.

You're trying to get leaderstats through ServerScriptService. That's not how you do it. leaderstats goes inside every player that joins in a game. So you would want to try something like this:

local leaderstats = player:WaitForChild("leaderstats")
local Pmulti = leaderstats:FindFirstChild("Multi")
Pmulti.Value = Pmulti.Value + 5 --Just a little test

I'm not sure as to how you're getting the player in this server script so I didn't include how I got a player. Hope this makes you understand a little more about leaderstats.

1 comment

0

thank you lol i forgot about that player is not in serverscript. i was so confused.i just made a dumb mistake

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