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

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

Asked by 4 years ago

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

Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
4 years ago

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!

0
Thanks! I appreciate it! Dreamhaunter89 21 — 4y
0
:D THANKS! I GOT A 200 POINTS MILESTONES! Xapelize 2658 — 4y
Ad
Log in to vote
0
Answered by
Hypgnosis 186
4 years ago

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)
0
That does not matter. Alphexus 498 — 4y
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. DeceptiveCaster 3761 — 4y
Log in to vote
0
Answered by
Alphexus 498 Moderation Voter
4 years ago
Edited 4 years ago

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)
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 vector3_zero 1056 — 4y

Answer this question