Issues with UserInputService

I’m trying to have a LinearVelocity’s LineVelocity value change when the player is seated & holding the Q key, and have the LineVelocity value change back to 0 upon exiting the seat/ stop holding the Q key. (I’ve rewritten the script several times in different ways and can’t get it to work)
image

local UIS = game:GetService("UserInputService")
local linear = script.Parent.LineVelocity
local player = script.Parent.Parent:FindFirstChild("SeatWeld").Part1.Parent.Humanoid

local Holding = false

UIS.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.Q and not Holding then
		Holding = true
		while Holding do
			linear.Value = 500
		end
	end
end)

UIS.InputEnded:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.Q and Holding then
		Holding = false
		linear.Value = 0
	end
end)

(Also, I’m not a scripter and I have no idea what im doing)

What exactly isn’t working, could you please specify? Are there any errors in the output?

No errors in output, the script just doesn’t seem to be doing anything

Did you check to see if the LinearVelocity value ever changes to 500? Also, try adding print statements to see which parts of the code may or may not be running.

I’ve used prints & checked to see if the value changes, but it hasn’t

I’ve just noticed that you are using a Server Script for this. You should be using a LocalScript as UserInputService only works with LocalScripts.

1 Like

If you want it as server replicated then do the first thing that @BabyNinjaTime said then create a RemoteEvent in ReplicatedStorage and name it whatever you want, after that create a Script in ServerScriptService and name it whatever you want too.

Code in the Script:

game:GetService("ReplicatedStorage").RemoteEvent_Name_Here.OnServerEvent:Connect(function(plr)
--Whatever you want here
end)

When ever the RemoteEvent is fired from the client whatever you put in the function will run.

How about adding a print to various parts of the script to see what the problem is?
first of all you have to know the problem and execute it clearly and tell us what happens

ANSWER

local linear = script.Parent.LineVelocity
local player = script.Parent.Parent:FindFirstChild(“SeatWeld”).Part1.Parent.Humanoid

local function onKeyPress(actionName, keyCode, inputState)
if actionName == “Q” and inputState == Enum.UserInputState.Begin then --or inputState == Enum.UserInputState.Change
linear.Value = 500
elseif actionName == “Q” and inputState == Enum.UserInputState.End then
linear.Value = 0
end
end

local userInputService = game:GetService(“UserInputService”)
userInputService.InputBegan:Connect(onKeyPress)
userInputService.InputEnded:Connect(onKeyPress)

QUESTION 2

What is the best way to make a game with a login and a server list?

What I mean by this is, how should I make a game with a login field and password field, and when you type in a username and password and click login, it takes you to a screen where you can click servers, and click them to get on one.

ANSWER