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

How do I get my script to go back to my part when I want it to?

Asked by 2 years ago
Edited by Shawnyg 2 years ago

My script:

local part = script.Parent

while true do
    wait(0.1)

    if game.Lighting.ClockTime < 6.1 then
        game.ReplicatedStorage.MoonScript.Parent = game.Workspace.TelescopeLookoutTeleporter        
        part.SunScript.Parent = game.ReplicatedStorage
    end
    if game.Lighting.ClockTime > 6 then
        game.ReplicatedStorage.SunScript.Parent = part
        part.MoonScript.Parent = game.ReplicatedStorage
    end
end
0
Cleaned up how your code visually looked for others to better read it Shawnyg 4330 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

You should consider putting them in the same script. I know you probably seperated them due the the loop, so let’s replace the loops.

An alternative would be to use coroutine, but in this case, :GetPropertyChangedSignal is a better choice.

local Lighting = game:GetService(‘Lighting’)

Lighting:GetPropertyChangedSignal(‘ClockTime’):Connect(function() --Whenever ClockTime changes, this event will fire, effectively replacing a loop
    if Lighting.ClockTime < 6.1 then
        --do stuff originally in “MoonScript” and stop whatever is in “SunScript”
    elseif Lighting.ClockTime > 6 then
        --do stuff originally in “SunScript” and stop whatever is in “MoonScript”
    end
end)
Ad

Answer this question