How do I do this? Because its already mapped to jumping, I cant change it. When I try to map a function to the A button, it just doesnt fire.
So I found a fix. I was using
game:GetService('UserInputService').InputBegan:connect(function(input,event)
if event then return end
--code
end)
While I shouldnt be using that event thing. That was preventing it from working as intended.
game:GetService('UserInputService').InputBegan:connect(function(input)
--code
end)
It’s not recommended to use UserInputService for this use case. This will trigger both the action that you assign to ButtonA, as well as make your character jump. Ideally, you’d like either one of the two to happen (your action when applicable, and otherwise jumping).
This can be achieved by using ContextActionService to bind functions to buttons. See in particular BindActionAtPriority. Set the priority to Enum.ContextActionPriority.High + 1 to make it run at a higher priority than the control script binding.
If you want to do your action but cancel a jump, you return Enum.ContextActionResult.Sink in the ContextActionService callback. If you want to do the jump instead, return Enum.ContextActionResult.Pass so that the input event gets passed to the control script.
Well, the function can only be fired when youre in space and in platformstand, so jumping doesnt interfere in my context
Hey, someone actually recommending my features! I’m proud.
I’d still recommend context action service in the off chance that you add another action that could be bound to A.
In the future you may like to bind more buttons to more actions. Then you may as well use CAS to keep things consistent.
CAS gives you more control of when your inputs are sunk and when they are allowed to pass through.
From my experience, binding everything to UserInputService is a headache because you’ll eventually run into conflicting inputs very quickly (especially on mobile where most inputs are touch) unless you make your own ContextActionService in lua (and why would you do that if it already exists?)