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

How would I set a specific key button w/ ContextActionService?

Asked by 5 years ago

I'm currently trying to make my weapon reload on the IOS. The Reload button works on the PC as "R" so how would I simply make it compatible for the IOS?

Here is my progress..

local contextActionService = game:GetService("ContextActionService")

function onKeyPress(actionName, userInputState, inputObject)
    if userInputState == Enum.UserInputState.Begin then
    end
end


local mobilebutton = game.ContextActionService:BindAction("keyPressSpecialName", onKeyPress, true, Enum.KeyCode.R)
contextActionService:SetPosition("SprintButton",UDim2.new(0.72,-25,0.20,-25))

The problem I'm facing is that when I press the button my weapon will not reload, but when I press 'R' it does reload (reload only when the script is inactive). The 'R' button won't work when the script is active & the positioning is broken for some reason.

TL;DR When button pressed, weapon won't reload when key set to "R"

Thank you! I appreciate the help.

Answer this question