Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Key Pressed and Button Pressed not working?

Asked by 5 years ago

So I've created a train, and I needed to make the doors open and close. The script worked; in a localscript which only opened it for the driver. I need it to work for the server as well. I put it into a normal script, change the functions and it still isn't working. The keypressed AND the button pressed isn't working.

--------------------------------------------------------------------------
-- // Variables \\ --
local train = script.Parent.Parent.Train.Value
local Variables = train.VehicleSeat.Variables
local LeftDoorVariable = Variables.LeftDoors
local RightDoorVariable = Variables.RightDoors
local LeftDoors1 = train.LeftDoor1
local LeftDoors2 = train.LeftDoor2
local RightDoors1 = train.RightDoor1
local RightDoors2 = train.RightDoor2
local seat = train.VehicleSeat
--------------------------------------------------------------------------
-- // Checkbox Reminder \\ --
-- Ticked = open
-- Unticked = closed
--------------------------------------------------------------------------
function LeftDoorsFunction()
if LeftDoorVariable.Value == false then

LeftDoors1.LDC1.Transparency = 1
LeftDoors1.LDO1.Transparency = 0
LeftDoors2.LDC2.Transparency = 1
LeftDoors2.LDO2.Transparency = 0
wait(0.5)
LeftDoors1.LDO1.Transparency = 1
LeftDoors1.LDFO1.Transparency = 0
LeftDoors2.LDO2.Transparency = 1
LeftDoors2.LDFO2.Transparency = 0
LeftDoorVariable.Value = true

elseif LeftDoorVariable.Value == true then

train.Sounds.DoorAlarm:Play()
wait(1.5)
LeftDoors1.LDFO1.Transparency = 1
LeftDoors1.LDO1.Transparency = 0
LeftDoors2.LDFO2.Transparency = 1
LeftDoors2.LDO2.Transparency = 0
wait(1.5)
LeftDoors1.LDO1.Transparency = 1
LeftDoors1.LDC1.Transparency = 0
LeftDoors2.LDO2.Transparency = 1
LeftDoors2.LDC2.Transparency = 0
train.Sounds.DoorAlarm:Stop()
LeftDoorVariable.Value = false
script.Disabled = true
end 
end


function RightDoorsFunction()
if RightDoorVariable.Value == false then

RightDoors1.RDC1.Transparency = 1
RightDoors1.RDO1.Transparency = 0
RightDoors2.RDC2.Transparency = 1
RightDoors2.RDO2.Transparency = 0
wait(0.5)
RightDoors1.RDO1.Transparency = 1
RightDoors1.RDFO1.Transparency = 0
RightDoors2.RDO2.Transparency = 1
RightDoors2.RDFO2.Transparency = 0
RightDoorVariable.Value = true

elseif RightDoorVariable.Value == true then

train.Sounds.DoorAlarm:Play()
wait(1.5)
RightDoors1.RDFO1.Transparency = 1
RightDoors1.RDO1.Transparency = 0
RightDoors2.RDFO2.Transparency = 1
RightDoors2.RDO2.Transparency = 0
wait(1.5)
RightDoors1.RDO1.Transparency = 1
RightDoors1.RDC1.Transparency = 0
RightDoors2.RDO2.Transparency = 1
RightDoors2.RDC2.Transparency = 0
train.Sounds.DoorAlarm:Stop()
RightDoorVariable.Value = false

end 
end
--------------------------------------------------------------------------
--game.Players.LocalPlayer:GetMouse().KeyDown:Connect(function(KeyPressed)
-- if KeyPressed == "[" then
-- LeftDoorsFunction()
 -- end
-- end)

--game.Players.LocalPlayer:GetMouse().KeyDown:Connect(function(KeyPressed)
-- if KeyPressed == "]" then
-- RightDoorsFunction()
--  end
-- end)

script.Parent.JunctionsTab.LeftDoors.MouseButton1Down:connect(LeftDoorsFunction)

game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
  if inputObject.KeyCode == Enum.KeyCode.LeftBracket then
    LeftDoorsFunction()
  end
end)

game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
  if inputObject.KeyCode == Enum.KeyCode.RightBracket then
    RightDoorsFunction()
  end
end)

And in case anyone needs the explorer: https://gyazo.com/aa88ecf4d758000908b65b4cd5a0f676

1
Use RemoteEvents. piRadians 297 — 5y
0
You sure about that? There is gonna be a lot of these trains. CarlPlandog 20 — 5y

Answer this question