I am making a game that involves helicopters and I need to be able to control the helicopters using an Xbox and keyboard inputs the keyboard input works just fine but the Xbox input doesn’t seem to be doing anything here is the full script:
LOCAL SCRIPT
local uis = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local inputEvent1 = game:GetService("ReplicatedStorage"):WaitForChild('Events'):WaitForChild('RemoteEvents'):WaitForChild('HelicopterMovementEvents'):WaitForChild('HelecopterControlsInp')
local helicopterControlsEvent2 = game:GetService("ReplicatedStorage"):WaitForChild('Events'):WaitForChild('RemoteEvents'):WaitForChild('HelicopterMovementEvents'):WaitForChild('HelecopterControlsInpB')
local helicopterControlsEvent3 = game:GetService("ReplicatedStorage"):WaitForChild('Events'):WaitForChild('RemoteEvents'):WaitForChild('HelicopterMovementEvents'):WaitForChild('HelecopterControlsInpL')
local helicopterControlsEvent4 = game:GetService("ReplicatedStorage"):WaitForChild('Events'):WaitForChild('RemoteEvents'):WaitForChild('HelicopterMovementEvents'):WaitForChild('HelecopterControlsInpR')
local takeControl = game:GetService("ReplicatedStorage"):WaitForChild('Events'):WaitForChild('RemoteEvents'):WaitForChild('HelicopterMovementEvents'):WaitForChild('TakeControl')
local isPilot = game:GetService("ReplicatedStorage"):WaitForChild('Values'):WaitForChild('IsPilot?')
local isInChat = false
local GuiService = game:GetService("GuiService")
local isMobile = game:GetService('UserInputService').TouchEnabled
uis.TextBoxFocused:Connect(function()
isInChat = true
end)
uis.TextBoxFocused:Connect(function()
isInChat = false
end)
local plr = game.Players.LocalPlayer
local GuiService = game:GetService("GuiService")
local uis = game:GetService("UserInputService")
local inputConnection
local controllerConnection
local function changeValue(v)
if v == "t" then
isPilot.Value = true
plr:WaitForChild("PlayerGui"):WaitForChild('FlightControls'):WaitForChild('Background').Visible = true
game:GetService('StarterGui'):SetCore("ResetButtonCallback", false)
if GuiService:IsTenFootInterface() then
plr:WaitForChild("PlayerGui"):WaitForChild('FlightControls'):WaitForChild('Background').Visible = false
plr:WaitForChild("PlayerGui"):WaitForChild('FlightControls'):WaitForChild('BackgroundXbox').Visible = true
end
if isMobile == true then
plr:WaitForChild("PlayerGui"):WaitForChild('FlightControls'):WaitForChild('Background').Visible = false
plr:WaitForChild('PlayerGui'):WaitForChild('MobileMoveControls'):WaitForChild('Background').Visible = true
end
elseif v == "f" then
isPilot.Value = false
game:GetService('StarterGui'):SetCore("ResetButtonCallback", true)
plr:WaitForChild("PlayerGui"):WaitForChild('FlightControls'):WaitForChild('Background').Visible = false
plr:WaitForChild("PlayerGui"):WaitForChild('FlightControls'):WaitForChild('BackgroundXbox').Visible = false
plr:WaitForChild('PlayerGui'):WaitForChild('MobileMoveControls'):WaitForChild('Background').Visible = false
end
end
local function take()
if isPilot.Value == true then
if not inputConnection then
inputConnection = uis.InputBegan:Connect(function(inp)
if inp.KeyCode == Enum.KeyCode.W and isInChat == false then
inputEvent1:FireServer()
end
if inp.KeyCode == Enum.KeyCode.S and isInChat == false then
helicopterControlsEvent2:FireServer()
end
if inp.KeyCode == Enum.KeyCode.A and isInChat == false then
helicopterControlsEvent3:FireServer()
end
if inp.KeyCode == Enum.KeyCode.D and isInChat == false then
helicopterControlsEvent4:FireServer()
end
end)
end
controllerConnection = game:GetService("RunService").Heartbeat:Connect(function()
local gamepads = uis:GetConnectedGamepads()
for _, gamepad in pairs(gamepads) do
if gamepad:GetGamepadType() == Enum.GamepadType.XboxOne then
if gamepad:IsButtonDown(Enum.KeyCode.DPadUp) and isInChat == false then
inputEvent1:FireServer()
elseif gamepad:IsButtonDown(Enum.KeyCode.DPadDown) and isInChat == false then
helicopterControlsEvent2:FireServer()
elseif gamepad:IsButtonDown(Enum.KeyCode.DPadLeft) and isInChat == false then
helicopterControlsEvent3:FireServer()
elseif gamepad:IsButtonDown(Enum.KeyCode.DPadRight) and isInChat == false then
helicopterControlsEvent4:FireServer()
end
end
end
end)
else
if inputConnection then
inputConnection:Disconnect()
inputConnection = nil
end
if controllerConnection then
controllerConnection:Disconnect()
controllerConnection = nil
end
end
end
isPilot.Changed:Connect(take)
takeControl.OnClientEvent:Connect(changeValue)
Thanks.