Hey, please can someone check this code?
you can skip these paragraphs but it just gives some context
Basically I'm trying to make two parts rotate at the same time but when I try to run this only the right part moves, I'm assuming this is because the function is only looking at the right part and not including the left part.
At some point I was able to make them both at least move but the left side literally spun around and popped into the same place as the right door where it basically did what the right part was doing (which I guess gave some hope) but I couldn't do anything because I didn't know why it happened.
This bit of code when ran shows only the right part moving
local TweenService = game:GetService("TweenService") local frontdoor = script.Parent local hingeL = script.Parent.frontdoors.HingeL local hingeR = script.Parent.frontdoors.HingeR local prompt = script.Parent.frontdoors.ProximityPrompt --left local goalOpen = {} goalOpen.CFrame = hingeL.CFrame * CFrame.Angles(0, math.rad(90), 0) local goalClose = {} goalClose.CFrame = hingeL.CFrame * CFrame.Angles(0, 0, 0) --right local goalOpen = {} goalOpen.CFrame = hingeR.CFrame * CFrame.Angles(0, math.rad(90), 0) local goalClose = {} goalClose.CFrame = hingeR.CFrame * CFrame.Angles(0, 0, 0) --play local tweenInfo = TweenInfo.new(1) local tweenOpen = TweenService:Create(hingeL, tweenInfo, goalOpen) local tweenClose = TweenService:Create(hingeL, tweenInfo, goalClose) local tweenOpen = TweenService:Create(hingeR, tweenInfo, goalOpen) local tweenClose = TweenService:Create(hingeR, tweenInfo, goalClose) prompt.Triggered:Connect(function() if prompt.ActionText == "Close" then tweenClose:Play() prompt.ActionText = "Open" else tweenOpen:Play() prompt.ActionText = "Close" end end)
hi there!
your issue is you are overriding the same two variables for both doors:
--left local goalOpen = {} goalOpen.CFrame = hingeL.CFrame * CFrame.Angles(0, math.rad(90), 0) local goalClose = {} goalClose.CFrame = hingeL.CFrame * CFrame.Angles(0, 0, 0) --right local goalOpen = {} goalOpen.CFrame = hingeR.CFrame * CFrame.Angles(0, math.rad(90), 0) local goalClose = {} goalClose.CFrame = hingeR.CFrame * CFrame.Angles(0, 0, 0)
.. the same with defining the tweening variables
--play local tweenInfo = TweenInfo.new(1) local tweenOpen = TweenService:Create(hingeL, tweenInfo, goalOpen) local tweenClose = TweenService:Create(hingeL, tweenInfo, goalClose) local tweenOpen = TweenService:Create(hingeR, tweenInfo, goalOpen) local tweenClose = TweenService:Create(hingeR, tweenInfo, goalClose)
the solution?
give these variables unique names for both sides
local LeftDoorData = {} local RightDoorData = {} -- create left door cframes LeftDoorData.OpenCFrame = hingeL.CFrame * CFrame.Angles(0, math.rad(90), 0) LeftDoorData.CloseCFrame = hingeL.CFrame -- create right door cframes RightDoorData.OpenCFrame = hingeR.CFrame * CFrame.Angles(0, math.rad(90), 0) RightDoorData.CloseCFrame = hingeR.CFrame
the same with the tween variables
--play local tweenInfo = TweenInfo.new(1) local tweenOpenLeft = TweenService:Create(hingeL, tweenInfo, LeftDoorData.OpenCFrame) local tweenCloseLeft = TweenService:Create(hingeL, tweenInfo, LeftDoorData.CloseCFrame) local tweenOpenRight = TweenService:Create(hingeR, tweenInfo, RightDoorData.CloseCFrame) local tweenCloseRight = TweenService:Create(hingeR, tweenInfo, RightDoorData.OpenCFrame)
.. so the code would look something like this:
local TweenService = game:GetService("TweenService") local frontdoor = script.Parent local hingeL = script.Parent.frontdoors.HingeL local hingeR = script.Parent.frontdoors.HingeR local prompt = script.Parent.frontdoors.ProximityPrompt local LeftDoorData = {} local RightDoorData = {} -- create left door cframes LeftDoorData.OpenCFrame = hingeL.CFrame * CFrame.Angles(0, math.rad(90), 0) LeftDoorData.CloseCFrame = hingeL.CFrame -- create right door cframes RightDoorData.OpenCFrame = hingeR.CFrame * CFrame.Angles(0, math.rad(90), 0) RightDoorData.CloseCFrame = hingeR.CFrame --play local tweenInfo = TweenInfo.new(1) local tweenOpenLeft = TweenService:Create(hingeL, tweenInfo, LeftDoorData.OpenCFrame) local tweenCloseLeft = TweenService:Create(hingeL, tweenInfo, LeftDoorData.CloseCFrame) local tweenOpenRight = TweenService:Create(hingeR, tweenInfo, RightDoorData.CloseCFrame) local tweenCloseRight = TweenService:Create(hingeR, tweenInfo, RightDoorData.OpenCFrame) prompt.Triggered:Connect(function() if prompt.ActionText == "Close" then tweenCloseLeft:Play() tweenCloseRight:Play() prompt.ActionText = "Open" else tweenOpenLeft:Play() tweenOpenRight:Play() prompt.ActionText = "Close" end end)