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

Im trying to change the text inside of a textlabel, but its not working, anything wrong?

So, im trying to change the text inside of a textlabel using a script, but it's not working, there are no errors inside of the output so there is nothing i know what i can do, here is my script, is there a problem with it?

local red = game:GetService("ReplicatedStorage").PointValues:FindFirstChild("RedPoints")

game.ReplicatedStorage.PointValues.RedPoints.Value.Changed:Connect(function()
	script.Parent.Text = red.Value
end)

3 answers

✓ Accepted answer

Hi! I think you have some problem that's is in the script, anyways, let fix this!

The script (not the answer, I just put here so that's make a lot of easier instead of always scrolling up to see this script.):

local red = game:GetService("ReplicatedStorage").PointValues:FindFirstChild("RedPoints")

game.ReplicatedStorage.PointValues.RedPoints.Value.Changed:Connect(function()
    script.Parent.Text = red.Value
end)

Line 3: You already have located 'RedPoints', and you need to use :GetService("ReplicatedStorage") instead of ReplicatedStorage. If the 'RedPoints' is already in the ReplicatedStorage while you're not in playing or running mode, then you'll just short-form the line 1, :FindFirstChild("RedPoints") to RedPoints. That's doesn't matter if you also use the :FindFirstChild() in line 1.

@StoicSage said, "Assuming that 'red' is an IntValue or NumberValue, you need to change it into a string". So, if that's an IntValue or NumberValue, then just place the tostring() inside! I don't need to describe anymore in here, you can just see the @StoicSage's answer.

You can just use while wait() do if you need to set the text to the "RedPoints'" value every time when the value was changed.

Yeah! Try to use those three ways to fix your problem! Let me repeat but short, use tostring() if 'RedPoints' was an IntValue or NumberValue, or use while wait() do when there you need to change the text while the "RedPoints" was changed.

If this fixes your issue, please mark this as correct so that might let everyone know that's this is the correct answer!

And please leave an upvote. I don't like to say, but it helps a lot! Thanks! :)

By the way, please don't blame me if there have no answer here, the script might not working if that not suits yours.

Yeha! So, I'm Jack_Roblox2008, see ya next time, bye bye!

2 comments

0

Thanks! I appreciate it!

0

:D THANKS! I GOT A 200 POINTS MILESTONES!

Assuming that 'red' is an IntValue or NumberValue, you need to change it into a string.

To do so, use tostring()

local red = game:GetService("ReplicatedStorage").PointValues:FindFirstChild("RedPoints")

game.ReplicatedStorage.PointValues.RedPoints.Value.Changed:Connect(function()
    script.Parent.Text = tostring(red.Value)
end)

2 comments

0

That does not matter.

0

Yes it does. Although Roblox may allow you to assign a number to a string property, you can't compare it to a string because it doesn't match the literal datatype. Assigning a string to a string property is following common sense and therefore is good practice.

The problem is that you're trying to use the Event .Changed on a property. That is not how it works. Also if you already set a variable for red. You should use it. Try this code instead.

local red = game:GetService("ReplicatedStorage").PointValues:FindFirstChild("RedPoints")

red.Changed:Connect(function()
	script.Parent.Text = red.Value
end)

1 comment

0

The Changed event of all “-Value” objects will pass the new value in to the connected function as an argument, so you could read this directly rather than accessing the Value property

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