Leaderstat Printing 0 When the Value Isn't 0

Basically, I have a leaderstat that is named “Money” and I have it because Im making a simulator type of game that doors open on a leaderstat value.

Im testing to see if the door isnt opening due to the value, and it was. I had my value as 2, and it was prinint 0.

Ive tried looking on different forums and videos but Im unable to find anything. Ive also made it so the value updates on the server side instead of the client side but it still didnt work.

This is a local script in starter gui. Its a local script because if it was a server side script everyone would have access to other player world purchases.

game.Players.PlayerAdded:Connect(function(player)
local leaderstats = instance.new("Folder")
leaderstats.Name = "leaderstats"

leaderstats.Parent = player
local Money = instance.new("IntValue")

Money.Name = "Money"
Money.Parent = leaderstats

--Have a script so when the player activates a proximity prompt it will give them 1 leaderstat value

print(Money.Value)
end)


Output: 0

1 Like

Because your print statement is in the “PlayerAdded” connection and not in the ProximityPrompt activated connection?

so from the look of this, the print(Money.Value) only gets triggered when they first load in, thus it never prints any changes.

Also question regarding the proximity prompt that changes the value, is the code for that on the client or server?

Client side. However through the developer console, i would give myself a leaderstat value and it would still print 0.

It is in the player added section.

first off I’d recommend that you dont change the value via the client, as by doing that, it becomes incredibly exploitable.

Do you have multiple print statements? Or do you just print the value on that line?

The problem is that that print statement only prints once, so any changes you make wont be printed. You’ll need to print the value after you’ve changed it.

So for the exploitable part, mabye a remote event? And mabye for the print statement ill add a wait delay. Ill give it a try!

you can tell when a proximity prompt is triggered on the server the same way you can tell when its triggered on the client, except its a little different, as on the server you dont have the player, but the triggered function provides the player like so:

local Prompt = YourPromptHere

Prompt.Triggered:Connect(function(Player)
    local MoneyValue = Player.leaderstats.Money
    MoneyValue.Value += 1
end)

Instead of using a wait delay, to tell when it changes you can use the :GetPropertyChangedSignal event to tell when it changes, example with your current code:

game.Players.PlayerAdded:Connect(function(player)
local leaderstats = instance.new("Folder")
leaderstats.Name = "leaderstats"

leaderstats.Parent = player
local Money = instance.new("IntValue")

Money.Name = "Money"
Money.Parent = leaderstats

Money:GetPropertyChangedSignal('Value'):Connect(function()
    print(Money.Value)
end)
end)
1 Like

Thank you! This worked and my output is now 2!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.