So, I am now very happy since I made my first Codelock door with GUI.
Not very important problem is that I don’t know how would I send data back to local script and then, the door would open.
This is because, currently the script first opens the door (few “animations” with for i loop) and then, the script returns data which closes GUI. How would I return data first and then open the door?
So, this is one part from my script. I want this thing "Success", true, false to put in before the door opens, not after that:
opened = true
thisDoor1Touch.Sound:Play()
thisDoor1Touch.Parent.Status.BrickColor = BrickColor.new("Lime green")
thisDoor1Touch.CanCollide = false
for i = 0.7,1,0.01 do
thisDoor1Touch.Transparency = i
wait()
end
wait(1)
thisDoor1Touch.Parent.Status.BrickColor = BrickColor.new("Black")
thisDoor1Touch.CanCollide = true
for i = 1,0.7,-0.01 do
thisDoor1Touch.Transparency = i
wait()
end
opened = false
return "Success", true, false
To solve this, you can use the spawn(foo) function. It will execute foo like as if it’s on a different script. So if you wrap the animation code for the door in spawn, it will run “separately” and allow for it to be “skipped” immediately to the return statement.
Here’s the fixed code:
spawn(function()
opened = true
thisDoor1Touch.Sound:Play()
thisDoor1Touch.Parent.Status.BrickColor = BrickColor.new("Lime green")
thisDoor1Touch.CanCollide = false
for i = 0.7,1,0.01 do
thisDoor1Touch.Transparency = i
wait()
end
wait(1)
thisDoor1Touch.Parent.Status.BrickColor = BrickColor.new("Black")
thisDoor1Touch.CanCollide = true
for i = 1,0.7,-0.01 do
thisDoor1Touch.Transparency = i
wait()
end
opened = false
end)
return "Success", true, false