[PROBLEM SOLVED]Need help with textbutton

i think i might know the problem so i think when i drive the bus the bus doors position moves and the script thinks its still in the same spot. How would i fix that problem or something like that i dont know? You can test out the scripts for yourself on studio to see if you want.

1 Like

I believe you will need to use CFrame for this. Unfortunately, though, I am inexperienced in CFrame, so I will not be able to provide any code related to CFrame. You can do some research on how you could move/position parts relative to another part (in this case position doors relative to the main component of the bus).

PS: I just thought of another way to do this without involving CFrame. You want to have 4 invisible parts in the bus; 2 for closed door positions and the other 2 for opened door positions. Make sure they are exactly positioned in the area you want the doors to go; 2 parts positioned where doors are closed, and the other 2 doors positioned to where the doors should move when opened. And also make sure they stay attached to the bus.

Here are 2 image example:

Consider the red part as the side of the bus and the 2 fully visible parts as the doors. The nearly transparent doors will be used to help position visible doors.


Here you can see that the doors have moved (opened), and you can see the transparent parts from where the visible doors were previously positioned.

So now you could either duplicate the same doors to position them and make them fully transparent, or just make new parts, resize them, and position them accordingly. Rename the closed invisible parts to "LeftClosedDoorInv and “RightClosedDoorInv”, and rename the ‘Opened’ invisible parts to “LeftOpenDoorInv” and “RightOpenDoorInv”. Parent the invisible ‘Right’ doors under RightBusDoor (where you also parented the main door), and parent the invisible ‘Left’ doors under the LeftBusDoor.

Now here is your updated script:

local TweenService = game:GetService("TweenService")

-- Create the RemoteEvent
local newEvent = Instance.new("RemoteEvent")
newEvent.Name = "DoorRequestEvent"
newEvent.Parent = game.ReplicatedStorage
print("The Remote event was made")

--timeout_number = 6

local remoteEvent = game.ReplicatedStorage:WaitForChild("DoorRequestEvent")



--local openGoalTable = {} -- you could insert any goal value involving the instance you are tweening (example: you could change size, position, transparency etc just by inserting the values in this table
--local closeGoalTable = {} -- same with this

--openGoalTable.Position = openleftPosition -- adds value to table
--closeGoalTable.Position = closedLeftPosition 




-- BUS DOORS
local LeftBusDoor = script.Parent.BusDoors.LeftBusDoor.LeftDoor
local RightBusDoor = script.Parent.BusDoors.RightBusDoor.RightDoor

local LeftClosedInv = script.Parent.BusDoors.LeftBusDoor.LeftClosedDoorInv
local LeftOpenInv = script.Parent.BusDoors.LeftBusDoor.LeftOpenDoorInv

local RightClosedInv = script.Parent.BusDoors.RightBusDoor.RightClosedDoorInv
local RightOpenInv = script.Parent.BusDoors.RightBusDoor.RightOpenDoorInv


-- Function to handle the door movement

local function handleDoorRequest(player, doorOpen)
	print(doorOpen)

	
	print("Found the Bus doors")


	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)

If you are able to open and close doors while the bus is moving, then using TweenService may not be a good idea, as the doors will be positioned slightly or significantly off, depending on how fast the bus is moving.

Edit:

A better method to move the doors, in this case, would either be to use RunService to slowly change the position of the doors (though this could be complicated), or use AlignPosition (and AlignOrientation if the doors are not anchored), which will also require more effort.
For now though, what I will do is position the doors to their exact spot right after the tween ends.
Now since I did this, you will need to have a cooldown for the button (about the same time as the tween time) to avoid the positioning getting mess up from button spamming. BTW, I have updated the script above at the time I saved this edit. If I make any new edits to the code, I will say it right below.

Apologies for the late reply

1 Like

Alright thanks man no worries ill try to add a cooldown and test thanks for helping me again :smiley:

1 Like

hey @BabyNinjaTime i keep getting this error LeftOpenDoorInv is not a valid member of Model “Workspace.Bus.Body.BusDoors.LeftBusDoor” even though theres a part called leftopendoorInv in that location.

Make sure the caps are the same in the name of the part, and that the parts are parented in the right location. If that does not resolve the error, you might need to add a WaitForChild when getting the instance, as sometimes the instance won’t load right away.

Edit:
I need to go somewhere, so I won’t be able to respond to any new replies for some time

Edit 2: I’m back now, did you face any issues while following the instructions in my post above?

ok so I fixed the error I told you from earlier but I don’t know man it still wont work here’s my script and I did everything you said

image

 local TweenService = game:GetService("TweenService")

-- Create the RemoteEvent
local newEvent = Instance.new("RemoteEvent")
newEvent.Name = "DoorRequestEvent"
newEvent.Parent = game.ReplicatedStorage
print("The Remote event was made")

--timeout_number = 6

local remoteEvent = game.ReplicatedStorage:WaitForChild("DoorRequestEvent")



--local openGoalTable = {} -- you could insert any goal value involving the instance you are tweening (example: you could change size, position, transparency etc just by inserting the values in this table
--local closeGoalTable = {} -- same with this

--openGoalTable.Position = openleftPosition -- adds value to table
--closeGoalTable.Position = closedLeftPosition 




-- 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")


	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)

What doesn’t work exactly? The doors still don’t move? Do the print statements show in the output?
Any other errors in the output?
Also, looking at the hierarchy image, I do not see any instance named LeftDoor or RightDoor, which should be the instances that we are supposed to move.

well its both it doesnt print if the doors open or close and the doors dont move. I keep clicking it just says nothing.

That’s an error message you are showing. It’s on the line that gets the Left Bus door. As I said above, that instance is not under the LeftBusDoor and RightBusDoor model, which is what is causing this new issue.
Parent the LeftDoor instance under the LeftBusDoor model, and parent the RightDoor instance under the RightBusDoor model

oh i see i thought an error was just red alright im gonna test it now.

1 Like

It’s usually red, the blue message right below the error message states the line and function of where the error is occurring in the specified script. But it appears you might have disabled ‘Errors’ in the All Messages button on the top left corner in the output tab.

wait I remember I changed the name of LeftDoor to LeftClosedDoorInv

You are supposed to have a total of 3 instances under both Bus Door models, 2 of which should be invisible.

oh ok i just fixed that right now time to test it im going to pray that it works lol

2 Likes

nope still didnt work Video: https://gyazo.com/c9eac7b2d9e65b1c625f299b559fc4f0

Any errors? Does it show the print statements? Go to the explorer tab, select one of the doors and check if the parts are even moving in the properties tab.
And also see if the door, as well as the invisible doors, are positioned correctly before and after pressing the button.

yup the print statements work again and nope they dont even move, theres no errors. Video: https://gyazo.com/55b79773d9824f1e6dc502e1ca8283c4

Have you checked if you set the position of LeftOpenDoorInv and RightOpenDoorInv away from the closed doors?

yeah i swear i moved it away from the closed door. Are you sure the script you did work and you tested it?

I haven’t tested it because I did not make the parts yet. I will try test the script myself now.