I can't change the text on a textLabel with a script

I want to make a tycoon.

Whenever an ore from a dropper is collected, the money total does not get updated on the money collector(there are no errors). When I try to change the text label’s text manually or with commands, it works so It probably isn’t a concatenation issue.
MoneyCollector.PNG

I did look somewhat briefly on the Developer Hub and on this forum, but nothing(in my opinion) was relevant. I tried adding a print statement containining the text on the (money!)collector and it did not match up with what was displayed.

I will try to explain away any confusion regarding this post so feel free to post your confusions.

-- function ore()
	local Dropper = game.Workspace.Dropper1v0
	local Crystal = Dropper.Crystal.Crystal
	local Core = Dropper.Crystal.Core
	local resetLoop = false
	while true do
		resetLoop = false
		Crystal.Anchored = true
		Core.Anchored = true
		Crystal.Position = Vector3.new(-0.539, 4.493, 41.146)
		Core.Position = Vector3.new(-0.539, 4.493, 41.146)
		Core.Orientation = Vector3.new(0, 0, 0)
		Core.Transparency = 1
		Crystal.CanCollide = false
		Crystal.Orientation = Vector3.new(0, 0, 0)
		Crystal.Transparency = 1
		Core.CanCollide = false
		wait(5)
		Crystal.CanCollide = true
		Crystal.Position = Vector3.new(-0.539, 4.493, 41.146)
		Crystal.Transparency = 0.6
		Core.CanCollide = true
		Core.Position = Vector3.new(-0.539, 4.493, 41.146)
		Core.Transparency = 0
		Crystal.Anchored = false
		Core.Anchored = false
		local part = Dropper.Crystal.Crystal
		local Amount = game.Workspace.Collector.Display.GUI.Amount
		local CurrencyToCollect = game.Workspace.Collector.Display.CurrencyToCollect.Value
		local function onPartTouched(otherPart)
			if otherPart == game.Workspace.Conveyor.Collector.TopLayer then
				Crystal.Anchored = true
				Core.Anchored = true
				Core.Orientation = Vector3.new(0, 0, 0)
				Core.Transparency = 1
				Crystal.CanCollide = false
				Crystal.Orientation = Vector3.new(0, 0, 0)
				Crystal.Transparency = 1
				Core.CanCollide = false
				Amount = ("$"..CurrencyToCollect)
				print(Amount)
				resetLoop = true
			end
		end

		part.Touched:Connect(onPartTouched)
		repeat wait() until resetLoop == true
	end
end

ore()

Tycoon_issue(1).wmv (1.6 MB)
The properties of the Crystal and the Core are all to move it to where it stands inside the dropper’s chute. Don’t suggest I use instantiation because this script, along with others(Not important to this topic), worked all right when the money was auto-collected.
(I don’t know how to make a gif)

1 Like

One thing that stands out is that you’re defining a function and a connection within a loop. What is the loop for?

It is to repeatedly ‘generate’ ores in a tycoon dropper.

PS: these are my very first posts.

Yes and the while true. I’m not sure why you would need them, is there a particular reason?

Oh alright so the problem here is that you’re including the connection and function definition within the loop. You’d want them to be outside so it connects every time the part is touched.

Your error is with setting the Amount value. Assuming game.Workspace.Collector.Display.GUI.Amount is a NumberValue, when you are setting the Amount variable you would do:

Amount.Value = "$"..CurrencyToCollect

I don’t understand… I don’t think that is an issue. Like I said in my first post, This script worked just fine when I used it when my tycoon auto-collected its money.

It is a string value. Amount is a TextLabel(think GUIs)

EDIT:Hold on… ‘Amount.Value’?! I thought it was ‘Amount.Text’

1 Like

Ok then try:

Amount.Text = "$"..CurrencyToCollect

I think it’s confused because it thinks your setting the variable to “$”…CurrencyToCollect.

Well for NumberValues you would do Amount.Value, as for TextLabels you would to Amount.Text.

It still doesn’t work. I added a .Text to the local Amount variable and I got the same result(fail!)

Do the .Text to when you are trying to change the text. For example, you would change this.
image

I tried that. Now even the printed amount isn’t properly updated. Any other ideas?

What is the printed amount at?

The printed Amount says “$0”(the quotes aren’t included), which is what it also says on the Money Collector.

Not sure if this is it, (but it might be) your function called ore is commented out, but the end isn’t and same with the last line where it is calling the function.

That is not an error. I just had a random guess at how to properly fit the script into the first post and didn’t remove the hyphens in the middle row of the script input. In a nutshell, the commenting hyphens(-) were from the default post fill-in. They are not in the actual script.

I’m not sure what is happening, so I think the best thing you could do right now is rework the script. When you remake it, make sure not to use a loop, or an event inside of the function.

Sighhhhh… The while loop is to spawn and respawn ores from the dropper onto the conveyor belt and the touched event is to detect if the ore has reached the end of the conveyor.

Woah woah woah, why are you defining a function inside of the loop?