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

Game not reading IntValue Correctly?

Asked by 4 years ago
Edited 4 years ago

Hello! I've been struggling with a bigger problem inside of my game for a bit now, and I finally found the problem. However, I'm not sure how to fix it.

When a player joins, a folder is created inside them (in addition to leaderstats, they are siblings) and there is an intvalue inside of that. Every time I print the value, it returns 0 no matter what.

It is inside of a for loop, so Players[i] is the local player

local Players = game.Players:GetChildren()
for i =1, #Players do
    local Spent = Players[i].folder.spent.Value
    print("Spent "..Spent)
end

This ALWAYS returns "Spent 0", and never returns an error

This is the code that changes it, it is in a textbutton in a localscript:


script.Parent.MouseButton1Click:Connect(function() local player = game.Players.LocalPlayer if player.leaderstats.Coins.Value > 4 then player.spent.Value = player.spent.Value + 5 player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - 5 end end)
0
The IntValue is being changed, right? xAtom_ik 574 — 4y
0
Yes, I tried doing it within my script and I tried changing the value in the explorer but neither worked Amanda314159 291 — 4y
0
Could we get the full code of your loop and when you set it? xAtom_ik 574 — 4y

1 answer

Log in to vote
0
Answered by
Gingerely 245 Moderation Voter
4 years ago

Hi! I know the answer. The variable spent is a constant. To fix this, all you have to do it delete the value in "local spent".

local Spent = Players[i].folder.spent
print("Spent "..Spent.Value)

Because when you just do local Spent = Players[i].folder.spent.Value , that is a constant that will never change.

0
Thanks! Amanda314159 291 — 4y
0
np :) Gingerely 245 — 4y
Ad

Answer this question