Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

1 comment

0

Cleaned up how your code visually looked for others to better read it

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.