So I made a client script and server side script for my textbutton that’s suppose to open the bus doors when the player clicks on it and if they click it again the doors close, but it wont work can anybody help me?
Client script
-- 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)
end
button.MouseButton1Click:Connect(onButtonClicked)
Server script
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)
2 Likes
Could it be that the “remoteEvent” variable in the Client script is returning nil? Creating new RemoteEvent’s do have their uses but seeing as you are creating it from a script it may not catch it in time to be set correctly as a variable.
Perhaps making the RemoteEvent through the explorer and referencing it through the path?
You could also try waiting for the instance, just to make sure that you actually set it as a variable.
game.ReplicatedStorage:WaitForChild("DoorRequestEvent", timeout_number)
I would suggest looking into using common debugging methods to help diagnose the problem.
Let me know how it goes!
1 Like
Hi i’m back again to tell you how it went,
so I tried debugging every line i got nothing no errors what do I do now?
1 Like
I did all of that but there were no errors but i suspect its the openPosition and closePosition might be wrong i dont know.
i updated my server script can anybody help it wont work
It appears you are only passing true to the server when firing the RemoteEvent from the LocalScript. Also, you do not need the Activated function in the server script, as the RemoteEvent already fires when the player clicks on that button.
Try using this for your LocalScript:
-- Locate the RemoteEvent
local remoteEvent = game.ReplicatedStorage.DoorRequestEvent
-- Locate the button
local button = script.Parent.OpenBusDoors
local doorsOpen = false -- I'm going to assume the bus doors are closed at the time this script runs
local function onButtonClicked()
doorsOpen = not doorsOpen -- sets 'doorsOpen' to the opposite value
remoteEvent:FireServer(doorsOpen)
if doorsOpen then
button.Text = "Close Bus Doors"
else
button.Text = "Open Bus Doors"
end
end
button.MouseButton1Click:Connect(onButtonClicked)
And this for your Server 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
-- Function to handle the door movement
local function handleDoorRequest(player, doorOpen)
print(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
if doorOpen then
tweenLeftOpen:Play()
tweenRightOpen:Play()
print("Door Opened")
else
tweenLeftClose:Play()
tweenRightClose:Play()
print("Door Closed")
end
end
-- Event listener for handling door requests
remoteEvent.OnServerEvent:Connect(handleDoorRequest)
Edit:
I’ve found a mistake I made, I have just edited the code. Copy and paste the code again.
uhh 1 problem how would i insert a goal value? sorry i’m a noob at this still learning.
I have already done that for you right below the table variables. (This was from your previous topic in my last post). Have you tried using the code I have given above?
the text changes fine now thanks for helping me on that but the doors dont move still and yes i did. Here is a video to show you https://gyazo.com/6c3adedd4519af886765bf38bd5ecdde
1 Like
Do the print statements show in the output? If so, which ones? If none show, maybe try removing the ‘timeout_number’ variable at the top of the script. I have updated the server script above.
it just shows this and it keeps printing that each time i click it but the problem is the doors wont move. Edit: Are you there?
I have reverted and also changed a few things in the server script. I have updated the code for the server script in my post above. Let me know what prints in the output.
this is what it printed now
I assume the doors still don’t move. Does it continue to print the same messages or is it different every time you click on the button again? I honestly do not see any other issue with the server script.
Edit: Have you confirmed that you are using the correct Position Values? You might be attempting to move the doors in the wrong position.
well it says the same thing but it says false, Found the bus doors, and door closed and i dont know either it might be the positions?
It could either have something to do with the positions, or with the instance variables you made. Confirm that the open and close positions are what originally wanted it to be. And also confirm if you are tweening the correct instances, as you might be tweening a different object.
no i dont think its tweening a diffrent object because i checked it so many times, by the way would I copy and paste the position of cframe or orgin position into the script? i feel like the positions have to be the problem.
I believe there is no difference between the two.
Looking at the video you sent, if the bus is able to move, then shouldn’t the positions you have put in the script be changed constantly? Because otherwise, the doors would technically be moving at a much further distance away from the bus.
Also,are you sure you want to move the position of the doors, because since they are bus doors, they technically should be rotated (this can be done using Orientation).
One more thing to ask; have you tried tweening the doors outside of this system, and did it work?
yeah the bus is able to move you helped me on that a few days ago and no i havent tried to tween the doors outside the system. I might do that to see. and if i rotate the bus doors the doors will look weird and glitch though the bus