ok ill watch some videos about that thanks. Edit would i weld all the parts or some parts?
uhhh i finally figured out how to weld it and it did the same thing and the doors are nowhere to be seen.
Print the Position of the doors so you can see where they’re at. I’m guessing you’ve CFramed them to world space and not object space.
I was going to mention the Anchoring thing. If the doors only open when the bus is completely stopped why don’t you anchor them as you have and unanchor them after the tween?
So like this? Edit: this sorta worked but now the doors dont move the way i want it to. Video:https://gyazo.com/9794ed58b0b2c740b39d255c2ec54fd5
local TweenService = game:GetService("TweenService")
local remoteEvent = game.ReplicatedStorage:WaitForChild("DoorRequestEvent")
-- BUS DOORS
local LeftBusDoor = script.Parent:WaitForChild("BusDoors"):WaitForChild("LeftBusDoor"):WaitForChild("LeftDoor")
local RightBusDoor = script.Parent:WaitForChild("BusDoors"):WaitForChild("RightBusDoor"):WaitForChild("RightDoor")
local LeftClosedInv = script.Parent:WaitForChild("BusDoors"):WaitForChild("LeftBusDoor"):WaitForChild("LeftClosedDoorInv")
local LeftOpenInv = script.Parent:WaitForChild("BusDoors"):WaitForChild("LeftBusDoor"):WaitForChild("LeftOpenDoorInv")
local RightClosedInv = script.Parent:WaitForChild("BusDoors"):WaitForChild("RightBusDoor"):WaitForChild("RightClosedDoorInv")
local RightOpenInv = script.Parent:WaitForChild("BusDoors"):WaitForChild("RightBusDoor"):WaitForChild("RightOpenDoorInv")
-- Function to handle the door movement
local function handleDoorRequest(player, doorOpen)
print(doorOpen)
print("Found the Bus doors")
for _, doorObj in pairs(script.Parent.BusDoors:GetDescendants()) do
if doorObj:IsA("BasePart") or doorObj:IsA("UnionOperation") then
doorObj.Anchored = true
--doorObj.CanCollide = false
end
end
local openLeftCFrame = LeftOpenInv.CFrame
local closedLeftCFrame = LeftClosedInv.CFrame
local openRightCFrame = RightOpenInv.CFrame
local closedRightCFrame = RightClosedInv.CFrame
local tweenInfo = TweenInfo.new(1)
local tweenLeftOpen = TweenService:Create(LeftBusDoor, tweenInfo, {CFrame = openLeftCFrame})
local tweenRightOpen = TweenService:Create(RightBusDoor, tweenInfo, {CFrame = openRightCFrame})
local tweenLeftClose = TweenService:Create(LeftBusDoor, tweenInfo, {CFrame = closedLeftCFrame})
local tweenRightClose = TweenService:Create(RightBusDoor, tweenInfo, {CFrame = closedRightCFrame})
-- Move the doors based on the doorOpen parameter
if doorOpen then
for _, doorObj in pairs(script.Parent.BusDoors:GetDescendants()) do
if doorObj:IsA("BasePart") or doorObj:IsA("UnionOperation") then
doorObj.Anchored = false
end
end
tweenLeftOpen:Play()
tweenRightOpen:Play()
print("Door Opened")
tweenRightOpen.Completed:Wait()
LeftBusDoor.CFrame = openLeftCFrame
RightBusDoor.CFrame = openRightCFrame
else
tweenLeftClose:Play()
tweenRightClose:Play()
print("Door Closed")
tweenRightClose.Completed:Wait()
LeftBusDoor.CFrame = closedLeftCFrame
RightBusDoor.CFrame = closedRightCFrame
end
end
print(LeftBusDoor.CFrame,RightBusDoor.CFrame)
-- Event listener for handling door requests
remoteEvent.OnServerEvent:Connect(handleDoorRequest)
I am trying to make something similar to this: https://gyazo.com/608057b1aa33bbe26a611189b8eec487
Your door model should only have it’s PrimaryPart Anchored when you Tween it. All the other door Parts should be welded to it and stay Unanchored.
Also, if the tween is finished why are you placing the door at the open or closed CFrame? It should already be there.
Well that makes the script move both bus doors to the closed bus door positions when the player clicks the button again to close the doors.
tweenLeftOpen:Play()
tweenRightOpen:Play()
print("Door Opened")
tweenRightOpen.Completed:Wait()
LeftBusDoor.CFrame = openLeftCFrame
RightBusDoor.CFrame = openRightCFrame
You play the tween, which puts the door at the open position, but then you CFrame it to the open Position again?
Oh wait I think your right I’m going to delete that from the script.
that didnt work also when I unanchored the other parts of the bus doors it did this. I don’t know why it keeps going to that spot
Where is the Pivot of the Anchored Door set? Are there any other Welds joining the door(s) to the bus?
You can see Welds as green lines if you go to the Models tab & select show Welds.
uhh no theres no welds joining the doors to the bus i checked the bus twice, the pivot of the anchored doors is set in 0,0,0 on pivotOffset.
So when you select the doors with the Move tool the drag handles are centered on the door?
Here’s a thought.
Why not simply use a HingeConstraint to pivot the doors (I’m assuming they pivot and don’t slide sideways) so you don’t need to Anchor and tween the parts at all.
You can set the HingeConstraint to Servo and just change the TargetAngle to 90 (or whatever angle works for you). If you set the AngularVelocity and the AngularResponsiveness you can get the doors to close realistically.
I also just reread your script.
local LeftClosedInv = script.Parent:WaitForChild("BusDoors"):WaitForChild("LeftBusDoor"):WaitForChild("LeftClosedDoorInv")
local LeftOpenInv = script.Parent:WaitForChild("BusDoors"):WaitForChild("LeftBusDoor"):WaitForChild("LeftOpenDoorInv")
local RightClosedInv = script.Parent:WaitForChild("BusDoors"):WaitForChild("RightBusDoor"):WaitForChild("RightClosedDoorInv")
local RightOpenInv = script.Parent:WaitForChild("BusDoors"):WaitForChild("RightBusDoor"):WaitForChild("RightOpenDoorInv")
What exactly are the items LeftClosedDoorInv
and LeftOpenDoorInv
that are referenced by the script?
Are they the names of Vector3.Values which would give the coordinates of the CFrame?
Otherwise I don’t see anywhere in the script that gives the actual CFrame Position of the doors.
The fact that your doors are moving to where you don’t want them should be the clue that those CFrame values aren’t being calculated properly.
the LeftClosedDoorInv is where the main bus doors close position is and LeftOpenDoorInv is where the main doors open position is. as you can see look. Edit: i used hinge constraints to pivot the doors it still does the same thing.
I think part of the issue is that you are CFraming the doors to the Position of the door, but not the ‘hinge’ of the door. Here’s a tutorial for tweening door rotation around a hinge Part. It does only work with an anchored hinge with the unanchored door welded to it. How to Tween / Animate a Door [2021 Tutorial] - Roblox - YouTube
But you can’t use a HingeConstraint as well as CFraming.
Here’s an old model sample I used to help someone out with scripting a house door.
You can use the exact same section of code (without the clickdetector firing it) that references the HingeConstraint and put the Attachment for the frame in the bus where you want it to pivot.
Door using HingeConstraints and script - Roblox
It’s the way I do all the doors in my vehicles. You can see the results here:
Tracked vehicle, suspension and racing tests. - Roblox
it still did the same thing i followed the tutorial you linked and everything.
local TweenService = game:GetService("TweenService")
h = script.Parent.BusDoorsRight.Hinge.HingeConstraint
val = script.Parent.Doors.Value
local remoteEvent = game.ReplicatedStorage:WaitForChild("DoorRequestEvent")
-- BUS DOORS
local LeftBusDoor = script.Parent:WaitForChild("BusDoorsLeft"):WaitForChild("LeftOpenDoorInv")
local RightBusDoor = script.Parent:WaitForChild("BusDoorsRight"):WaitForChild("RightOpenDoorInv")
local LeftClosedInv = script.Parent:WaitForChild("BusDoorsLeft"):WaitForChild("LeftClosedDoorInv")
local LeftOpenInv = script.Parent:WaitForChild("BusDoorsLeft"):WaitForChild("LeftDoor")
local RightClosedInv = script.Parent:WaitForChild("BusDoorsRight"):WaitForChild("RightClosedDoorInv")
local RightOpenInv = script.Parent:WaitForChild("BusDoorsRight"):WaitForChild("RightBusDoor")
-- Function to handle the door movement
local function handleDoorRequest(player, doorOpen)
print(doorOpen)
print("Found the Bus doors")
for _, doorObj in pairs(script.Parent.BusDoors:GetDescendants()) do
if doorObj.Name == "LeftDoor" or doorObj.Name == "RightDoor" then
doorObj.Anchored = true
--doorObj.CanCollide = false
end
end
local openLeftCFrame = LeftOpenInv.CFrame
local closedLeftCFrame = LeftClosedInv.CFrame
local openRightCFrame = RightOpenInv.CFrame
local closedRightCFrame = RightClosedInv.CFrame
local tweenInfo = TweenInfo.new(1)
local tweenLeftOpen = TweenService:Create(LeftBusDoor, tweenInfo, {CFrame = openLeftCFrame})
local tweenRightOpen = TweenService:Create(RightBusDoor, tweenInfo, {CFrame = openRightCFrame})
local tweenLeftClose = TweenService:Create(LeftBusDoor, tweenInfo, {CFrame = closedLeftCFrame})
local tweenRightClose = TweenService:Create(RightBusDoor, tweenInfo, {CFrame = closedRightCFrame})
-- Move the doors based on the doorOpen parameter
if (val.Value == false) then
val.Value = true
h.TargetAngle = -90
tweenLeftOpen:Play()
tweenRightOpen:Play()
print("Door Opened")
tweenRightOpen.Completed:Wait()
else
val.Value = false
h.TargetAngle = 0
tweenLeftClose:Play()
tweenRightClose:Play()
print("Door Closed")
tweenRightClose.Completed:Wait()
end
end
print(LeftBusDoor.CFrame,RightBusDoor.CFrame)
-- Event listener for handling door requests
remoteEvent.OnServerEvent:Connect(handleDoorRequest)
You can’t do both!
Surround the whole tween/anchor sections with --[[ your code section ]]
brackets and let the new code you wrote handle just the HingeConstraints.
local TweenService = game:GetService("TweenService")
h = script.Parent.BusDoorsRight.Hinge.HingeConstraint
val = script.Parent.Doors.Value
local remoteEvent = game.ReplicatedStorage:WaitForChild("DoorRequestEvent")
-- BUS DOORS
--[[local LeftBusDoor = script.Parent:WaitForChild("BusDoorsLeft"):WaitForChild("LeftOpenDoorInv")
local RightBusDoor = script.Parent:WaitForChild("BusDoorsRight"):WaitForChild("RightOpenDoorInv")
local LeftClosedInv = script.Parent:WaitForChild("BusDoorsLeft"):WaitForChild("LeftClosedDoorInv")
local LeftOpenInv = script.Parent:WaitForChild("BusDoorsLeft"):WaitForChild("LeftDoor")
local RightClosedInv = script.Parent:WaitForChild("BusDoorsRight"):WaitForChild("RightClosedDoorInv")
local RightOpenInv = script.Parent:WaitForChild("BusDoorsRight"):WaitForChild("RightBusDoor") ]]
-- Function to handle the door movement
local function handleDoorRequest(player, doorOpen)
print(doorOpen)
print("Found the Bus doors")
--[[ for _, doorObj in pairs(script.Parent.BusDoors:GetDescendants()) do
if doorObj.Name == "LeftDoor" or doorObj.Name == "RightDoor" then
doorObj.Anchored = true
--doorObj.CanCollide = false
end
end
local openLeftCFrame = LeftOpenInv.CFrame
local closedLeftCFrame = LeftClosedInv.CFrame
local openRightCFrame = RightOpenInv.CFrame
local closedRightCFrame = RightClosedInv.CFrame
local tweenInfo = TweenInfo.new(1)
local tweenLeftOpen = TweenService:Create(LeftBusDoor, tweenInfo, {CFrame = openLeftCFrame})
local tweenRightOpen = TweenService:Create(RightBusDoor, tweenInfo, {CFrame = openRightCFrame})
local tweenLeftClose = TweenService:Create(LeftBusDoor, tweenInfo, {CFrame = closedLeftCFrame})
local tweenRightClose = TweenService:Create(RightBusDoor, tweenInfo, {CFrame = closedRightCFrame}) ]]
-- Move the doors based on the doorOpen parameter
if (val.Value == false) then
val.Value = true
h.TargetAngle = -90
--tweenLeftOpen:Play()
--tweenRightOpen:Play()
print("Door Opened")
--tweenRightOpen.Completed:Wait()
else
val.Value = false
h.TargetAngle = 0
--tweenLeftClose:Play()
--tweenRightClose:Play()
print("Door Closed")
--tweenRightClose.Completed:Wait()
end
end
--print(LeftBusDoor.CFrame,RightBusDoor.CFrame)
-- Event listener for handling door requests
remoteEvent.OnServerEvent:Connect(handleDoorRequest)
You’re handling the door logic on the client, but you shouldn’t. Try printing doorsOpen on the server, it’s probably nil
The main doors still dont stay at the same spot
But why are they moving that far away if they are attached to the bus with HingeConstraints and you are no longer CFraming them or tweening them?
Do you have another section of code that is still CFraming the doors?
No i dont so i dont know whats causing that. Edit i think this is causing it? or no
local TweenService = game:GetService("TweenService")