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

Attempt to index a nil Value?

Asked by 3 years ago
Edited 3 years ago

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.

0
i messed up on the script part babtrick 0 — 3y
0
Please put this in a code block iivSnooxy 248 — 3y
0
ok yeah sorry i did that but didnt work babtrick 0 — 3y
0
There finally it worked in a code block babtrick 0 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

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.

Ad
Log in to vote
0
Answered by 3 years ago

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.

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

Answer this question