Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Just started keybind stuff and got stuck. Help?

Hi. I've just started doing keybinds and already have got stuck. This keybind should only work when you're sat in VehicleSeat and click "C".

local click = game.Players.LocalPlayer:GetMouse()
local bus = script.Parent.Value.Value
click.KeyDown:connect(function(key)
if key=="c" then
bus.Body.Lights.Blinkers.RightValue.Value = true
end
end)

3 comments

0

ur not even checking if the player is in the car (and no i dont know yet how to check that, just telling to that u need to add that in)

0

To check if the player is seated there's a property in humanoids called Sit. I'm not sure how to check if the player is sitting in a specific seat tho

0

Nevermind there's a property in VehicleSeats called 'Occupant'. It gets the humanoid sitting in the seat

2 answers

This seems to be a localscript so you should probably use userinputservice as it is very useful other than using player's mouse you could use it like the following for your certain action.

local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(InputKey, gameProcess)
	if gameProcess then return end --If the player is chatting then ignore his input
	if InputKey.KeyCode == Enum.KeyCode.C then --Check if the keyPressed was the Key C you can change this to any key you want
		--Your actions here
	end
end)

Hope this helped.

Hello!

You should use UserInputService. Here's a simple code I've made for you.

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(Input, Box)
	if Input.KeyCode == Enum.KeyCode.G and not Box then
		print("Key G has been pressed!")
	end
end)
  • Input = The input of the player. (Can be a keyboard key, a mouse click etc.)
  • Box = A boolean value (true/false). If the player is focused on a TextBox such as chat, it will return true, if the player is not focused on a TextBox it will return false.

Remember: Input is an object. That's why you have to do Input.KeyCode.

This discussion is preserved as it was. New answers, comments, and votes are closed.