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

My TextLabel's text doesn't change when I run this script?

Asked by
Suamy 68
7 years ago
Edited 7 years ago

I'm building an airport with a friend, and I want to make a single main script that handles all the functions that the airport does.

There is a SurfaceGui in the airport that shows departure times (in seconds). I managed to make a NumberValue stored in a Folder count down, but I need to make it so the time shows on the screen as well.

My friend somehow did this without using tostring() for the NumberValue, but he used multiple scripts, which I want to avoid, since it's very unorganized.

Below I'll post my script and then my friends' scripts. These are normal Scripts placed in Workspace.

My script:

local airport = game.Workspace.Airport
local booths = game.Workspace.Airport.Booths
local screen = game.Workspace.Airport.AirportTV
local screen2 = game.Workspace.Airport.AirportTV2
local times = game.Workspace.Airport.DepartureTimes

-- air canada departure times
while times.AirCanada.Value > -1 do
    wait (1)
    times.AirCanada.Value = times.AirCanada.Value - 1
    if times.AirCanada.Value == 0 then 
    times.AirCanada.Value = 120     
    end
end

game.Workspace.Airport.DepartureTimes.AirCanada.Changed:connect(function()-- numbervalue
    local val = game.Workspace.Airport.DepartureTimes.AirCanada
    local label = game.Workspace.Airport.AirportTV.TVScreen.SurfaceGui.AirCanada.Arrival

    label.Text = tostring(val.Value)
end)

Friend's scripts

--script 1
while wait(1) do
    script.Parent.Value = script.Parent.Value - 1
    if script.Parent.Value == -1 then
        script.Parent.Value = 120
    end
end
--script 2

while wait() do
    script.Parent.Text = script.Parent.Time.Value
end

My friend has a habit of making scripts "while wait() do" -_-

0
Maybe use your friends script, If it works, then try using it, if it causes lag, then I see why you want only one script theawesome624 100 — 7y
0
Ok. So try putting your event connection before the while loop. GoldenPhysics 474 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago

From what I can tell your script should be ok but there are two thing that should be looked at, 1st.

game.Workspace.Airport.DepartureTimes.AirCanada.Changed:connect(function(ins) -- there is variable for what has changed so I would use it 
     local val = game.Workspace.Airport.DepartureTimes.AirCanada
        local label = game.Workspace.Airport.AirportTV.TVScreen.SurfaceGui.AirCanada.Arrival
    label.Text = tostring(val.Value)
end)

2nd

--this loop will not show the changes as the event has not been added 
while times.AirCanada.Value > -1 do
    wait (1)
    times.AirCanada.Value = times.AirCanada.Value - 1
    if times.AirCanada.Value == 0 then 
    times.AirCanada.Value = 120     
    end
end

I would use a thread for this task as you said you wanted to a script that will do more than one task Constructing_a_thread

local airport = game.Workspace.Airport
local booths = game.Workspace.Airport.Booths
local screen = game.Workspace.Airport.AirportTV
local screen2 = game.Workspace.Airport.AirportTV2
local times = game.Workspace.Airport.DepartureTimes

-- this will add the thread then allow the rest of your code to run
spawn(function()    while times.AirCanada.Value > -1 do
        wait (1)
        times.AirCanada.Value = times.AirCanada.Value - 1
        if times.AirCanada.Value == 0 then 
        times.AirCanada.Value = 120     
        end
    end
end)

game.Workspace.Airport.DepartureTimes.AirCanada.Changed:connect(function()-- numbervalue
    local val = game.Workspace.Airport.DepartureTimes.AirCanada
    local label = game.Workspace.Airport.AirportTV.TVScreen.SurfaceGui.AirCanada.Arrival

    label.Text = tostring(val.Value)
end)

Hope this helps

Ad
Log in to vote
1
Answered by
einsteinK 145
7 years ago
Edited 7 years ago

This is how your script looks:

local variables = values

while wait(1) do
    -- stuff
end

AirCanada.Changed:connect(function() end)

The while-loop will go on forever. The code after the loop will never run, so the AirCanana.Changed:connect() neither. A simple fix would be connecting the event before starting the while-loop.

A combined version would be this:

local airport = game.Workspace.Airport
local booths = airport.Booths
local screen = airport.AirportTV
local screen2 = screen.AirportTV2
local times = airport.DepartureTimes
local tvscreen = screen.TVScreen
local gui = tvscreen.SurfaceGui

-- air canada departure times
while times.AirCanada.Value > -1 do
    wait (1)
    local value = times.AirCanada.Value - 1
    if value == 0 then 
        value = 120     
    end
    times.AirCanada.Value = value
    gui.AirCanana.Arrival.Text = tostring(value)
end

Although it is advised to use WaitForChild.

Answer this question