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

Stats not updating in this surfacegui?

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

3 comments

2

It isn't finding the child Money in the object player. Did you double check to see if it is there?

1

Below line 4 add a check to make sure money exists. Ex. if not money then return end

0

That fixed it, but the value doesn't seem to change.

1 answer

✓ Accepted answer

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)

1 comment

0

there was a slight bug but I fixed it. Remove value and change money to player.Money

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