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

Stats not updating in this surfacegui?

Asked by
yoshi8080 445 Moderation Voter
8 years ago

I was taking a tycoon kit, making it slightly better, but I can't seem to get the stat value to work. Help?

EDIT: Added another check

owner = script.Parent.Parent.Parent.Parent.Owner.Value -- This is the tycoon owner, aka playername
plrService = game:GetService('Players')
player = plrService:WaitForChild(owner):FindFirstChild("Value")
 -- Checks players for the ownervalue
if (player ~= nil) then
money = player:WaitForChild('Money')
if not money then
    print('No money')
    return end
while wait(1) do
print(player)
    if not player then
script.Parent.Text = 'Money: 0'
else
script.Parent.Text = 'Money: '..money.Value
end
end
end
end
2
It isn't finding the child Money in the object player. Did you double check to see if it is there? BlackJPI 2658 — 8y
1
Below line 4 add a check to make sure money exists. Ex. if not money then return end User#11440 120 — 8y
0
That fixed it, but the value doesn't seem to change. yoshi8080 445 — 8y

1 answer

Log in to vote
2
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
8 years ago

A better way to load the owner's stats would be to update it every time the owner's value is changed. You can do this using the Changed event of value:

local owner = script.Parent.Parent.Parent.Parent.Owner

owner.Changed:connect(function(value)
    if value then
        local player = game.Players[value]
        if player then
            local value = player.Value
            local money = value.Money
            -- Code
        end
    end
end)
0
there was a slight bug but I fixed it. Remove value and change money to player.Money yoshi8080 445 — 8y
Ad

Answer this question