I'm currently trying to make a system where you an set the direction with Keybinds: R (Forward) F (Neutral) and V (Reserve) Nothing happens. I tried doing print("Test") but It didn't work either.
I'll preferably use normal script but I aslo tried it with local script.
Can anyone help me?
local UIS = game:GetService("UserInputService") local seat = script.Parent local F = script.Parent.Forward local N = script.Parent.Neutral local R = script.Parent.Reverse while seat.Occupant ~= nil do UIS.InputBegan:Connect(function(input, gameProcessedEvent) if input.UserInputType == Enum.UserInputType.Keyboard then local key = input.KeyCode if key == Enum.KeyCode.R then if F == false then F.Value = true R.Value = false N.Value = false else F.Value = false R.Value = false N.Value = true end elseif key == Enum.KeyCode.V then F.Value = false R.Value = true N.Value = false else F.Value = false R.Value = false N.Value = true end elseif input.KeyCode == Enum.KeyCode.F then N.Value = true F.Value = false R.Value = false end end) wait(0.1) end
Thanks in advance
The UserInputService actually is only client side so you will have to use a localscript to get the user input. You can send this information from the client to the server with remotefunctions or remoteevents, and then go from there.
Here's something I threw together as kind of an example of how you could send the input across:
Local Script in StarterPlayerScripts
local UIS = game:GetService("UserInputService") local seat = game.Workspace:WaitForChild("Seat") local event = seat.RemoteEvent local players = game:GetService("Players") local keycode = Enum.KeyCode local keys = {keycode.F, keycode.N, keycode.R} --Send info when input begins UIS.InputBegan:connect(function(input, processed)--Get input if seat.Occupant == players.LocalPlayer.Character.Humanoid then --check if the input should be sent if input.UserInputType == Enum.UserInputType.Keyboard then --check if the input is the right type for i,v in ipairs(keys) do --find out if the input is one of the right keys if input.KeyCode == v then event:FireServer(input.KeyCode, "began") --trigger the event for the server end end end end end) --Send info when input ends UIS.InputEnded:connect(function(input, processed) if seat.Occupant == players.LocalPlayer.Character.Humanoid then if input.UserInputType == Enum.UserInputType.Keyboard then for i,v in ipairs(keys) do if input.KeyCode == v then event:FireServer(input.KeyCode, "ended") end end end end end)
Script inside the seat
local event = script.Parent.RemoteEvent local forward = false local reverse = false local neutral = false function handleinput(player, input, inputtype: string) print(player.Name.." "..inputtype.." "..tostring(input)) if input = Enum.KeyCode.F then if inputtype = "began" then forward = true else forward = false end elseif input = Enum.KeyCode.R then if inputtype = "began" then reverse = true else reverse = false end else if inputtype = "began" then neutral = true else neutral = false end end end event.OnServerEvent:Connect(handleinput)
From these I bet you could figure out a way to make it work with what you had going, hopefully this will help!
Edit: I edited the script portion to show you how you could setup your bool values. I haven't run this myself and typed it directly in here so hopefully I didn't mistype anything.
Ok I tried this as a normal script and as a local script, both of them didn't work.
local event = script.Parent.RemoteEvent local forward = false local reverse = false local neutral = false function handleinput(player, input, inputtype: string) print(player.Name.." "..inputtype.." "..tostring(input)) if input == Enum.KeyCode.R then if inputtype == "began" then forward = true else forward = false end elseif input == Enum.KeyCode.V then if inputtype == "began" then reverse = true else reverse = false end elseif input == Enum.KeyCode.F then if inputtype == "began" then neutral = true else neutral = false end end end event.OnServerEvent:Connect(handleinput) local F = script.Parent.Forward local N = script.Parent.Neutral local R = script.Parent.Reverse if forward == true then F.Value = true elseif forward == false then F.Value = false end if neutral == true then N.Value = true elseif forward == false then N.Value = false end if reverse == true then R.Value = true elseif forward == false then R.Value = false end