I made a bus in my roleplay game but I don’t have anything to open the bus doors, how would I make a textbutton that opens the bus doors and closes when the player clicks it again?
Edit: this is the script i’m working on it wont work
local TweenService = game:GetService("TweenService")
local textbutton = script.Parent.Parent["A-Chassis Tune"].Plugins.AC6_Stock_Gauges.OpenBusDoors
-- Create the RemoteEvent
local remoteEvent = Instance.new("RemoteEvent")
remoteEvent.Name = "DoorRequestEvent"
remoteEvent.Parent = game.ReplicatedStorage
print("The Remote event was made")
timeout_number = 6
local remoteEvent = game.ReplicatedStorage:WaitForChild("DoorRequestEvent", timeout_number)
-- Function to handle the door movement
local function handleDoorRequest(player, doorOpen)
local LeftBusDoor = script.Parent.BusDoors.LeftBusDoor.LeftDoor
local RightBusDoor = script.Parent.BusDoors.RightBusDoor.RightDoor
print("Found the Bus doors")
local openleftPosition = Vector3.new(619.376, 17.451, 17.868) -- Replace with the desired open position
local openRightPosition = Vector3.new(619.376, 17.451, 17.868) -- Replace with the desired open position
local closedLeftPosition = Vector3.new(619.069, 17.451, 16.603) -- Replace with the desired closed position
local closedRightPosition = Vector3.new(619.069, 17.451, 16.603) -- Replace with the desired closed 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
textbutton.Activated:Connect(handleDoorRequest)
if doorOpen then
if textbutton.Text == "Close Bus Doors" then
tweenLeftClose:Play()
tweenRightClose:Play()
textbutton.Text = "Open Bus Doors"
print("Door Opened")
else
tweenLeftOpen:Play()
tweenRightOpen:Play()
textbutton.Text = "Close Bus Doors"
print("Door Closed")
end
end
end
-- Event listener for handling door requests
remoteEvent.OnServerEvent:Connect(handleDoorRequest)
Hello,
you could use RemoteEvents where the client would send a request to open/close the doors when the button is pressed and then the server would open/close the doors in your Script.
You can do a simple door system by modifying the CFrame of the doors, Tweening them, or animating them.
I’m doing a script of what you said but I’m having a problem making it work.
The local script for the button
-- Client Script (LocalScript)
-- Locate the RemoteEvent
local remoteEvent = game.ReplicatedStorage.DoorRequestEvent
-- Locate the button
local button = script.Parent.OpenBusDoors
local function onButtonClicked()
-- Send a door request to the server
remoteEvent:FireServer(true) -- Replace 'true' with the desired door state
end
button.MouseButton1Click:Connect(onButtonClicked)
The Server-sided script
local remoteEvent = Instance.new("RemoteEvent")
remoteEvent.Name = "DoorRequestEvent"
remoteEvent.Parent = game.ReplicatedStorage
-- Function to handle the door movement
local function handleDoorRequest(player, doorOpen)
local LeftBusDoor = workspace.Bus.Body.BusDoors.LeftBusDoor.LeftDoor
local RightBusDoor = workspace.Bus.Body.BusDoors.RightBusDoor.RightDoor
local openPosition = Vector3.new(0, 5, 0) -- Replace with the desired open position
local closedPosition = Vector3.new(0, 0, 0) -- Replace with the desired closed position
-- Move the doors based on the doorOpen parameter
if doorOpen then
LeftBusDoor:TweenPosition(openPosition, Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 1, true)
RightBusDoor:TweenPosition(openPosition, Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 1, true)
else
LeftBusDoor:TweenPosition(closedPosition, Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 1, true)
RightBusDoor:TweenPosition(closedPosition, Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 1, true)
end
end
-- Event listener for handling door requests
remoteEvent.OnClientEvent:Connect(handleDoorRequest)
local TweenService = game:GetService("TweenService")
local textbutton = script.Parent.Parent["A-Chassis Tune"].Plugins.AC6_Stock_Gauges.OpenBusDoors
-- Create the RemoteEvent
local remoteEvent = Instance.new("RemoteEvent")
remoteEvent.Name = "DoorRequestEvent"
remoteEvent.Parent = game.ReplicatedStorage
print("The Remote event was made")
timeout_number = 6
local remoteEvent = game.ReplicatedStorage:WaitForChild("DoorRequestEvent", timeout_number)
-- Function to handle the door movement
local function handleDoorRequest(player, doorOpen)
local LeftBusDoor = script.Parent.BusDoors.LeftBusDoor.LeftDoor
local RightBusDoor = script.Parent.BusDoors.RightBusDoor.RightDoor
print("Found the Bus doors")
local openleftPosition = Vector3.new(619.376, 17.451, 17.868) -- Replace with the desired open position
local openRightPosition = Vector3.new(619.376, 17.451, 17.868) -- Replace with the desired open position
local closedLeftPosition = Vector3.new(619.069, 17.451, 16.603) -- Replace with the desired closed position
local closedRightPosition = Vector3.new(619.069, 17.451, 16.603) -- Replace with the desired closed 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
textbutton.Activated:Connect(handleDoorRequest)
if doorOpen then
if textbutton.Text == "Close Bus Doors" then
tweenLeftClose:Play()
tweenRightClose:Play()
textbutton.Text = "Open Bus Doors"
print("Door Opened")
else
tweenLeftOpen:Play()
tweenRightOpen:Play()
textbutton.Text = "Close Bus Doors"
print("Door Closed")
end
end
end
-- Event listener for handling door requests
remoteEvent.OnServerEvent:Connect(handleDoorRequest)