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

How can I disable a value based off another value?

I've been trying to disable a value based on another value for a certain amount of time. Came up with this, my 3rd version of it. Any better ways I can recreate this or at least make this version work?


while true do
	repeat wait() until CC.CurrentTrackNumber.Value==22 
	script.Parent.Value.Value = true
	wait(5)
	OpenGates()
	wait(15)
	CloseGates()
	wait(5)
	script.Parent.Value.Value = false
end 

CC=game.Workspace.CoasterCFrameV4Beta

--Ignore functions \/

function OpenGates()
	local gateopenparts=CC.OpenGates:GetChildren()
	local gateclosedparts=CC.ClosedGates:GetChildren()
	for i=1,#gateopenparts do
		gateclosedparts[i].Transparency=1
		gateclosedparts[i].CanCollide=false
		gateopenparts[i].Transparency=0
		gateopenparts[i].CanCollide=true
	end
end

function CloseGates()
	local gateopenparts=CC.OpenGates:GetChildren()
	local gateclosedparts=CC.ClosedGates:GetChildren()
	for i=1,#gateopenparts do
		gateclosedparts[i].Transparency=0
		gateclosedparts[i].CanCollide=true
		gateopenparts[i].Transparency=1
		gateopenparts[i].CanCollide=false
	end
end

1 answer

✓ Accepted answer

Your method is pretty plausible, I don't believe this is much better but it's a lot simpler, you could write it like this?

spawn(function()
   while wait() do --// Sometimes you can forget to write a delay, and overload the Server
      if CC.CurrentTrackNumber.Value == 22 then
         fullProcess()
         script:FindFirstAncestor("Value").Value = false
         break --// I assume you want this to only happen once, if not, simply just remove the 'break'
      end
   end
end)

function fullProcess() --// The cleaner the better
   wait(5); OpenGates(); wait(15); CloseGates(); wait(5)
end

It's also best if you define functions before running a loop as they won't technically be defined yet, I just fixed this by seperating the loop into another thread.

if you have any more auestions or anything else to specify please let me know

Hope this helps

1 comment

0

Thanks, looks like I need to study a bit more.

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