How do I get a IntValue into a TextLabel.Text?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make a SpeedGUI, which shows the player the current speed he is traveling at. What currently works is the driving and the GUI showing up to the player after he sat down.
  2. What is the issue? Include screenshots / videos if possible!
    So if the Train drives forward, the IntValue gets changed to its current speed. Now the TextLabel isn’t changing and just staying at 0. My guess is, that the IntegerValue of the Number and StringValue of the TextLabel aren’t cooperating.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried looking up for Integer/ String converters or functions, but couldn’t find any helpful.
-- This is the GUI Giver
local Players = Game:GetService("Players")
local workspace = Game:GetService("Workspace")

local Seat = script.Parent
local GUI = script.TestGui
local Active = false
local Player = nil
local NewGui = nil

Seat.ChildAdded:connect(function(Child)
	if Active == false then
		if Child.Name == "SeatWeld" then
			Active = true
			Player = Players:GetPlayerFromCharacter(Child.Part1.Parent)
			if Player ~= nil then
				PlayerGui = Player:FindFirstChild("PlayerGui")
				if PlayerGui ~= nil then
					NewGui = GUI:Clone()
					NewGui.Parent = PlayerGui
				end
			end
		end
	end
end)

Seat.ChildRemoved:connect(function(child)
	if child.Name == "SeatWeld" then
		if Active == true then
			Active = false
			pcall(function() NewGui:Destroy() end)
			Player = nil
			NewGui = nil
		end
	end
end)

while true do
	GUI.Frame.TextLabel.Text = Seat.SpeedInt.Value
	wait(1)
end
-- This is the DriveScript
while true do
	wait()
	if script.Parent.Throttle == 1 then
		script.Parent.SpeedInt.Value = script.Parent.SpeedInt.Value + 1
		wait(.3)
	end
	if script.Parent.Throttle == -1 then
		script.Parent.SpeedInt.Value = script.Parent.SpeedInt.Value - 1
		wait(.3)
	end
	if script.Parent.Throttle == -1 then
		script.Parent.SpeedInt.Value = 0
		wait()
	end
	script.Parent.BodyVelocity.Velocity = script.Parent.CFrame.LookVector * (script.Parent.SpeedInt.Value)
end

This is the TrainChassis if you want to look at it.
TrainChassis.rbxm (12,1 KB)

The Hierarchy
image

2 Likes

Could you include a photo of the Explorer hierarchy? It would help a lot. :slight_smile:

What I would do, is when you clone your NewGui variable, is use the Changed event which will detect any changes (Or value) made to your IntValue

Try this:

-- This is the GUI Giver
local Players = Game:GetService("Players")
local workspace = Game:GetService("Workspace")

local Seat = script.Parent
local GUI = script.TestGui
local Active = false
local Player = nil
local NewGui = nil

Seat.ChildAdded:connect(function(Child)
	if Active == false then
		if Child.Name == "SeatWeld" then
			Active = true
			Player = Players:GetPlayerFromCharacter(Child.Part1.Parent)
			if Player ~= nil then
				PlayerGui = Player:FindFirstChild("PlayerGui")
				if PlayerGui ~= nil then
					NewGui = GUI:Clone()
					NewGui.Parent = PlayerGui
                    Seat.SpeedInt.Changed:Connect(function(NewValue)
                        NewGui.Frame.TextLabel.Text = tostring(NewValue)
                    end)
				end
			end
		end
	end
end)

Seat.ChildRemoved:connect(function(child)
	if child.Name == "SeatWeld" then
		if Active == true then
			Active = false
			pcall(function() NewGui:Destroy() end)
			Player = nil
			NewGui = nil
		end
	end
end)

Also TextLabel.Text is a string, so you need to convert your IntValue using a tostring() function

1 Like

Have you tried printing the SpeedInt.Value? Possibly using tonumber() / tostring()?

How would you use the toString()-Function in this scenario?

tostring() just basically converts a variable to a string

Example:

local Number = 50

print(tostring(Number))
--Would Output as "50" in a string

Plus I already gave the reference

Somehow it worked with the script you gave me 5min ago… what did you change to that?
(The one without the tostring thingy)

You can assign a number to a string property and it will automatically convert it to a string, tostring is only needed for other data types (boolean, nil, userdata)

Your original script had a loop inside these specific lines:

From what I’m understanding, you’re just only changing that specific GUI property from the server side which isn’t working on your client side

Cloning the GUI would just do nothing, since you’re not referencing a loop inside that GUI either

Understood it now, thanks for the help y’all! :grinning:

1 Like