I am making a door, and when a button is pressed, 2 doors open. And then it waits 5, then it goes in more. But for some reason, it won’t close. And I ran out of ideas, I checked the dev foum, Youtube, everything.
Script:
local detector = script.Parent.ClickDetector
local button = script.Parent
local left = game.Workspace.GateLeft
local right = game.Workspace.GateRight
game.Players.ChildAdded:Connect(function()
detector.MouseClick:Connect(function()
local goal = {}
goal.Position = left.Position + Vector3.new(0, 0, 18)
local Info = TweenInfo.new(1)
local tween = TweenService:Create(left, Info, goal)
tween:Play()
local goal = {}
goal.Position = right.Position + Vector3.new(0, 0, -18)
local Info = TweenInfo.new(1)
local tween = TweenService:Create(right, Info, goal)
tween:Play()
wait(5)
if right.Position == "-159.523, 8.504, -115.867" then
local goal = {}
goal.Position = left.Position + Vector3.new(0, 0, -18)
local Info = TweenInfo.new(1)
local tween = TweenService:Create(left, Info, goal)
local goal = {}
goal.Position = right.Position + Vector3.new(0, 0, 18)
local Info = TweenInfo.new(1)
local tween = TweenService:Create(right, Info, goal)
tween:Play()
else
print("The position is false, don't move")
end
end)
end)
Well, Positions aren’t made from Strings. They’re made from Vector3. You need to do: if right.Position == Vector3.new(-159.523, 8.504, -115.867) then or input the whatever the correct coordinates are.
Thank you, I uh, fixed it. One problem was the position, so I removed that, and I accidently removed tween:Play() So I fixed that, and it started working again. Thanks, I wouldn’t have checked without you.
Working script for anyone else who sees this post:
local detector = script.Parent.ClickDetector
local button = script.Parent
local left = game.Workspace.GateLeft
local right = game.Workspace.GateRight
game.Players.ChildAdded:Connect(function()
detector.MouseClick:Connect(function()
local goal = {}
goal.Position = left.Position + Vector3.new(0, 0, 18)
local Info = TweenInfo.new(1)
local tween = TweenService:Create(left, Info, goal)
tween:Play()
local goal = {}
goal.Position = right.Position + Vector3.new(0, 0, -18)
local Info = TweenInfo.new(1)
local tween = TweenService:Create(right, Info, goal)
tween:Play()
wait(10)
local goal = {}
goal.Position = left.Position + Vector3.new(0, 0, -18)
local Info = TweenInfo.new(1)
local tween = TweenService:Create(left, Info, goal)
tween:Play()
local goal = {}
goal.Position = right.Position + Vector3.new(0, 0, 18)
local Info = TweenInfo.new(1)
local tween = TweenService:Create(right, Info, goal)
tween:Play()
end)
end)
Hmm, well if the doors are models, or parts, lol, id recommend tweening the CFrame instead of the position, such as:
local Detector = script.Parent.ClickDetector
local Button = script.Parent -- What is this actually??
local LeftDoor = workspace.GateLeft
local RightDoor = workspace.GateRight
local Players = game:GetService("Players")
local TS = game:GetService("TweenService")
local TweenInformation = TweenInfo.new()
local GoalLeft = {CFrame = CFrame.new()}
local GoalRight = {CFrame = CFrame.new()}
local ReturnLeft = {CFrame = CFrame.new()}
local ReturnRight = {CFrame = CFrame.new()}
Players.PlayerAdded:Connect(function() -- what is this for? the Detector should work indefinitely
Detector.MouseClick:Connect(function()
local LeftAnimate = TS:Create(LeftDoor,TweenInformation,GoalLeft)
local RightAnimate = TS:Create(RightDoor,TweenInformation,GoalRight)
LeftAnimate:Play()
RightAnimate:Play()
LeftAnimate.Completed:Connect(function(playbackState)
if playbackState == Enum.PlaybackState.Completed then
wait(10)
local LeftReturn = TS:Create(LeftDoor,TweenInformation,ReturnLeft)
local RightReturn = TS:Create(RightDoor,TweenInformation,ReturnRight)
end
end)
end)
end)
This should work, since the button being pressed will cause the door to open, then once completed, wait 10 seconds, and finally make a return tween.
Of course fill in the TweenInfo.new() and other parameters and it should work just fine
Well yeah, but the reverse will happen immediately after the door is fully open, kinda making the door a bit hard to traverse , unless of course if the tween time is long enough. But making a return tween allows us to control when the door will close again
Delay only applies to when the tween starts, but not midway . Wouldn’t it be cool for another parameter stating the delay between the start of the tween and the reversal?