Hello, I’m trying to make a gun with reload buttons for mobile player. Normally for PC players they just need to press R to reload. But I don’t know how to make for mobile players. Can anyone teach pls?
You need to use ContextActionService. This service allows you to link input and functions. And this service will also help to make a recharge button for mobile devices. Create a recharge function, then connect it to the button using BindAction, then put the button a position and a picture using SetPosition and SetImage. More about the service.
local ContextActionService = game:GetService("ContextActionService")
local ACTION_RELOAD = "Reload"
local tool = script.Parent
local function handleAction(actionName, inputState, inputObject)
if actionName == ACTION_RELOAD and inputState == Enum.UserInputState.Begin then
print("Reloading!")
end
end
tool.Equipped:Connect(function ()
ContextActionService:BindAction(ACTION_RELOAD, handleAction, true, Enum.KeyCode.R)
end)