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

How do I change the cash value display when the ore's cash value changes?

This is the whole script. I'm trying to make a tycoon game. I need the cash value that is displayed above the part to change when the part's cash value gets changed. I just need make the function detect when the cash value has been changed. Or do I have to do a loop to make sure it always see the cash value. Meaning a while loop to alway check the cash value so, when the cash value changes, the cash display also changes to whatever the cash value is.. Any help will be appreciated! Ty

wait(2)
workspace:WaitForChild("PartStorage")

deb = true 
script.Parent.Clicker.ClickDetector.MouseClick:connect(function(wat)
	if deb == true then
		deb = false
			local part = Instance.new("Part",workspace.PartStorage)
			local cash = Instance.new("StringValue",part)
			local upgrade = Instance.new("StringValue",part)
			local board = Instance.new("BillboardGui",part)
			local text = Instance.new("TextBox",board)
			part.BrickColor = BrickColor.new("Medium stone grey")
			cash.Name = "Cash"
			cash.Value = 1
			upgrade.Name = "Tags"
			upgrade.Value = 0
			board.Size = UDim2.new(0,75,0,25)
			board.StudsOffset = Vector3.new(0,1.5,0) 
			board.MaxDistance = 30
			text.Size = UDim2.new(0,75,0,25)
			text.TextXAlignment = "Center"
			text.TextYAlignment = "Center"
			text.Font = "Legacy"
			text.TextSize = 20
			text.BackgroundTransparency = 1
			text.Text = "$"..cash.Value
			part.CFrame = script.Parent.Drop1.CFrame - Vector3.new(0,1.3,0)
			part.Size = Vector3.new(1, 1, 1) -- Size of the drops
			part.TopSurface = "Smooth"
			part.BottomSurface = "Smooth"
			game.Debris:AddItem(part,20) -- How long until the drops expire
			wait(0.35)
			deb = true
			cash.Value.Changed:connect(function(changedd)
				changedd.Cash.Value = "$"..cash.Value
			end)

	end
end)

``

1 answer

✓ Accepted answer

On line 36, you are changing the cash value, but you should be changing the text of the ui element.

cash.Changed:Connect(function(newValue)
	text.Text = "$" .. tostring(newValue)
end)

You should use the .Changed event on the cash object, because it will check when the value is changed.

Hope this helps :)

p.s. change all of your connects to Connect. The former is deprecated. Also, for performance improvement, don't use the Instance.new(type, parent), instead use local a = Instance.new(type) then set the parent after using a.Parent = parent.

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