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

Xbox Controls Not Working With Keydown?

Asked by 5 years ago

I've made a script for xbox controls by just using keydown, but it does not work it gives me the error of: "Keydown is not a valid member of ControllerService", please help?

local player = game.Players.LocalPlayer
repeat wait() until player.Character.Humanoid
local humanoid = player.Character.Humanoid
local mouse = player:GetMouse()
local XboxButton = game:GetService("ControllerService")

XboxButton.KeyDown:connect(function(key)
 if key == "x" then
    game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Health = 0
    end
end)

1 answer

Log in to vote
0
Answered by 5 years ago

The error explains itself. The KeyDown event does not exist on the ControllerService. You attempted an event similar to Mouse.KeyDown, which the mouse event is deprecated and should not be used in new work. Use UserInputService.

--LocalScript

local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local UIS = game:GetService"UserInputService"

UIS.InputBegan:Connect(function(key) -- Use :Connect, :connect is deprecated

    if key.KeyCode == Enum.KeyCode.ButtonX then --Xbox button X code
        char:BreakJoints()
    end
end)
Ad

Answer this question