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

Just started keybind stuff and got stuck. Help?

Asked by 5 years ago

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)
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) Gameplayer365247v2 1055 — 5y
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 DaBrainlessOne 129 — 5y
0
Nevermind there's a property in VehicleSeats called 'Occupant'. It gets the humanoid sitting in the seat DaBrainlessOne 129 — 5y

2 answers

Log in to vote
0
Answered by
Divistern 127
5 years ago

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.

Ad
Log in to vote
0
Answered by
JakyeRU 637 Moderation Voter
5 years ago

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.

Answer this question