Hey, I’ve been developing a game for a long time. I’m currently with the cars and they start manually with a button, start button.
How can I trigger the button by pressing B on an Xbox controller or F on the keyboard as an example?
I’m not gonna write a wiki article here but in short proximity prompts. You want to have it be a parent of a attachment then in your code you want to bind a event called “PromptTriggered” from the “ProximityPromptService” service to a annonymous function (yes we are gonna be assigning the data manually) then you need to pass in the proximity prompt instance as the first parameter of the annonymous function.
so i should add ProximityPrompt to The button ? because i made a start button for the car if u click it with mouse the car is starting but now i want to make it triggerable with Xbox Button B and Keyboard Key like F
yea just replace your click detector with the proximity prompt
:3 that not part it’s a TextButton xd and for text button u don’t need a ClickDetector
oh my bad its like 1 am i probably read over something. ig what u could do is like have the code be binded to key press too since thats kinda what you are already doing by doing like button.mousebutton1click:Connect(function() end)
just make this
function()
end
make it actually be referenced and not annonymous and just bind it to your text button event and your keyboard event (userinput service)
ContextActionService
seems like the solution for this, try something like this:
local context = game:GetService("ContextActionService")
local function startCar(actionName, inputState, inputObj)
if inputState == Enum.UserInputState.Begin then
-- Car start logic here --
end
return Enum.ContextActionResult.Pass
end
-- Bind the action when they enter the car --
context:BindAction('StartCar', startCar, false, Enum.KeyCode.ButtonB)
-- Make sure to unbind the action when they exit the car --
--context:UnbindAction('StartCar')
i hate to be that person on the forum but why would you overcomplicate the code base by using the cas system for something that is a linear event
ContextActionService
is a clean solution for this case. I apologize if this is complicated, I just gave an example of a simple use. This is the type of example they give on dev hub as well.
what if there was a textbutton, then it was activated, and the proximity was activated?