Displaying number on a TextLabel

  1. I’m trying to make a GUI which multiplies a number which is typed by the player in TextBox and it is displayed on a TextLabel.

  2. Everything’s working, the number which is typed in the TextBox is being multiplied perfectly. But I’m stuck at displaying the number on the TextLabel.

  3. I couldn’t find anything on DevForum about this issue…

 TextLabel = game.StarterGui.ScreenGui.Frame.TextLabel
numb = 0.0035

textbox = script.Parent.FocusLost:Connect(function(enter)
	
		print(script.Parent.Text * numb)
	
end)

TextLabel.Text = textbox

I suck at scripting… still learning. Any help is appreciated!

1 Like

You could just set the textlabels text to the multiplied number.

 TextLabel = game.StarterGui.ScreenGui.Frame.TextLabel
numb = 0.0035

textbox = script.Parent.FocusLost:Connect(function(enter)
	
		print(script.Parent.Text * numb)
        TextLabel.Text = tonumber(script.Parent.Text * numb)
end)
1 Like

i think i see the problem

to update an uiobject you need to use playergui
try

game.Players.LocalPlayer.PlayerGui

instead of

also
use local scripts for this

2 Likes
local Player = game:GetService("Players").LocalPlayer
local TextLabel = Player:WaitForChild("PlayerGui"):WaitForChild("ScreenGui"):WaitForChild("Frame"):FindFirstChild("TextLabel")
local Number = 0.0035
local textbox = script.Parent
textbox.FocusLost:Connect(function(enter)
    if tonumber(script.Parent.Text)  then
        print(script.Parent.Text * Number)
    end
end)

TextLabel.Text = textbox

Notice, instead of this -
local TextLabel = Player:WaitForChild("PlayerGui"):WaitForChild("ScreenGui"):WaitForChild("Frame"):FindFirstChild("TextLabel")

You could simply assign it as you did to your textbox. Just assign it to where its currently located , but dont use StarterGui.

Note
This will only make the change to the client, not to the whole server.

3 Likes

You should get every players gui and change the textlabel.

StarterGui service is only used to change the gui that will be shown to the player when it joins or respawns.

To change a gui while playing you should acces the client’s gui.

You could change every player’s gui with remote events or a for loop.

the easiest way to do it is with a foor loop.

for i, players in ipairs(game.Players:GetChildren()) do
players.PlayerGui.ScreenGui.Frame.TextLabel.Text = tonumber(script.Parent.Text * numb)
end

Note that using this method makes the server change the gui of every player so if you edit it from client side the script wont thake those changes into consideration.

It is recommended to avoid working with UI’s through the server like this, read more at :
[You can sometimes]

[You could use remotes tho].

Ye, you could just use FireAllClients()

1 Like

Well, there are 2 issues:

  1. the path to the TextLabel should be game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.TextLabel (if this is a local script).

  2. You can’t multiply strings with numbers. But we have the tonumber function for this. Then we’ll have something like:

 TextLabel = game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.TextLabel
numb = 0.0035

textbox = script.Parent.FocusLost:Connect(function(enter)
	
		print(tonumber(script.Parent.Text) * numb)
	
end)

TextLabel.Text = textbox

How could you multiply a string with a number?

local answer = script.Parent.Text * numb

print(script.Parent.Text, answer)

use tonumber and then check if the tonumber result is equal to a number using type

Hi @Valkyrop, I’ve tried your code in Roblox Studio but sadly it didn’t work. I placed the code (Local Script) inside the “Textbox”. Let me know if I placed the local script in the wrong place.!

I’ve tried this code in Visual Studio Code and it worked perfectly…!:

salary = 1000
numb = 0.0035

-- TODO

print("$".. salary * numb)

Terminal (Output):
image

1 Like