Opening Doors only works one time and after the whole bus just doesnt drive

Hello,

So here’s the problem when I click the text button to open the doors they work the first time right but then after the bus is undriveable oh and also the bus worked before i clicked it, i’d appreciate it so much if someone helped me. Here’s a video showing it: https://gyazo.com/cb8a59a21b6e777de460aafc6aae0571

Server Script

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 openleftPosition = LeftOpenInv.Position 
	local closedLeftPosition  = LeftClosedInv.Position
	local openRightPosition	 = RightOpenInv.Position
	local closedRightPosition = RightClosedInv.Position

	local tweenInfo  = TweenInfo.new(1)

	local tweenLeftOpen = TweenService:Create(LeftBusDoor, tweenInfo, {Position = openleftPosition})
	local tweenRightOpen = TweenService:Create(RightBusDoor, tweenInfo, {Position = openRightPosition})

	local tweenLeftClose = TweenService:Create(LeftBusDoor, tweenInfo, {Position = closedLeftPosition})
	local tweenRightClose = TweenService:Create(RightBusDoor, tweenInfo, {Position = closedRightPosition})

	-- Move the doors based on the doorOpen parameter

	if doorOpen then
		tweenLeftOpen:Play()
		tweenRightOpen:Play()
		print("Door Opened")

		tweenRightOpen.Completed:Wait()
		LeftBusDoor.Position = LeftOpenInv.Position
		RightBusDoor.Position = RightOpenInv.Position
	else
		tweenLeftClose:Play()
		tweenRightClose:Play()
		print("Door Closed")

		tweenRightClose.Completed:Wait()
		LeftBusDoor.Position = LeftClosedInv.Position
		RightBusDoor.Position = RightClosedInv.Position
	end
end


-- Event listener for handling door requests
remoteEvent.OnServerEvent:Connect(handleDoorRequest)

Client script for the text button

local remoteEvent = game.ReplicatedStorage.DoorRequestEvent
local button = script.Parent.OpenBusDoors

local doorsOpen = false
local cooldownActive = false
local cooldownDuration = 4 -- Cooldown duration in seconds

local function onButtonClicked()
	if not cooldownActive then
		doorsOpen = not doorsOpen
		remoteEvent:FireServer(doorsOpen)
		cooldownActive = true

		if doorsOpen then
			button.Text = "Close Bus Doors"
		else
			button.Text = "Open Bus Doors"
		end

		wait(cooldownDuration)
		cooldownActive = false
	end
end

button.MouseButton1Click:Connect(onButtonClicked)
2 Likes

Hello, as I can’t see the client script, are there any errors while running this code? ( press F9 or enable output log )

1 Like

oh sorry here’s the client script.

local remoteEvent = game.ReplicatedStorage.DoorRequestEvent
local button = script.Parent.OpenBusDoors

local doorsOpen = false
local cooldownActive = false
local cooldownDuration = 4 -- Cooldown duration in seconds

local function onButtonClicked()
	if not cooldownActive then
		doorsOpen = not doorsOpen
		remoteEvent:FireServer(doorsOpen)
		cooldownActive = true

		if doorsOpen then
			button.Text = "Close Bus Doors"
		else
			button.Text = "Open Bus Doors"
		end

		wait(cooldownDuration)
		cooldownActive = false
	end
end

button.MouseButton1Click:Connect(onButtonClicked)
1 Like

The problem seems to come from the server, are there any errors while u run this code? ( press F9 to see developer console ) | Sorry I’m on mobile and I can’t test the script at the moment

1 Like

yes i know the problem is coming from the server script and no theres no errors in the script, the bus just wont move after i click it.

2 Likes

Uh, as I see the code only returns true but at the same time the code lines changes? Are u sure you are using only 1 script that use the remote event?

1 Like

Yes im sure its just the server script thats the problem.

1 Like

try to remove the local from local function on server code and client code

1 Like

nope that didnt work i still cant drive the bus after i click it.

1 Like

Hold on, so you are telling me the doors make the bus doesn’t move? But do you have a custom configuration for the bus to make it move?

1 Like

well kinda like that but when I click the button in the video i showed u the bus just doesn’t want to drive. Im using a-chassis for the bus.

1 Like

Are the doors welded or completely parented in the model

1 Like

Yes there parented in the model.
image

1 Like

Alright, as you are using Parts, I don’t recommend using Position while changing the position or tween of a part. Not sure if this will work but try to change Position to CFrame.

1 Like

well im not gonna use parts for the final model im gonna make my own bus door models but this is just a test.

1 Like

Read this full ….twentyonecharacters

1 Like

uhh I used cframe instead of position still did nothing.

1 Like

Yeah the problem is anchoring the parts to the model making it impossible to move, I just saw now u typed that. You have to use another way than anchoring a part. You can try welding.

1 Like

how would i weld the parts in the script?

1 Like

You don’t weld them in the script, that would be complicated for you, you weld them using welds. Watch some videos about them as I can’t explain u how to weld parts as a video would

1 Like