i want to convert a string (intValue) to a instance (TextLabel).
how do i do this?
i want to convert a string (intValue) to a instance (TextLabel).
how do i do this?
It’s pretty simple use
tonumber() or tostring()
here an example :
I want to convert “10” :
local MyString = "10"
MyString = tonumber(MyString)
i am just getting the error Unable to assign property Text. string expected, got nil
this is my code:
server:
local fuel = workspace.car.values.fuel.Value
fuel = math.random(5, 50)
fuel = math.floor(fuel)
while wait(1) do
if workspace.car.chassis.Velocity.Magnitude > 5 then
fuel = fuel - 0.1
print(fuel)
end
end
local script:
wait(5)
while wait(1) do
script.Parent.Text = tonumber(workspace.car.values.fuel)
end
how do i fix this?
oops i did a mistake sorry
it’s
wait(5)
while wait(1) do
script.Parent.Text = tostring(workspace.car.values.fuel)
end
turns down i also made a mistake by not writing fuel.Value, but i am how experiencing another problem:
as you see in the video, after the wait(5), instead of being changed the fuel value, it gets changed to 0. why is that and how do i fix it?
okay i got it
so try this in the server script :
local fuel = workspace.car.values.fuel
fuel.Value = math.random(5, 50)
fuel.Value = math.floor(fuel.Value)
while wait(1) do
fuel.Value = fuel.Value - 0.1
print(fuel.Value)
end
You got an error: Attempt to index nil with 'PlayerGui'.
Try using Player:WaitForChild("PlayerGui"), but even then gui should be controlled on the client.
Edit the fuel value on the server, and use GetPropertyChangedSignal() to edit the text on the client.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.