How to make gun reload buttons for mobile player

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?

This is my gun:
https://www.roblox.com/library/5493948081/Assualt-Rifle-for-devforum

And this is my remote events script which put in the ServerScriptService
https://www.roblox.com/library/5460768054/GunServer

2 Likes

Use context action service, and :BindAction() and it creates button for mobile users

Can’t you just make a text button wouldn’t that be more simple?

:BindAction() is really simple, it automatically creates a button!

I tried the to use the text button but it didnt work

Oh really but im sorry that I dont have a deep knowledge about :BindAction()

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.

What is your code for the button?

Here’s answer

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)

It will give you a button saying ‘reload’!

2 Likes

Where to put this script? 30charrssssssss

You’ll need to use ContextActionService here is a link to the Developer Hub:

We just talked about it
They tell me to browse it

Should I put it in StarterPlayerScript?

I read his script, it looks like it should be placed inside of a LocalScript, inside of the tool.

2 Likes

I’m sorry I got to go
I will reply you as soon as possible

You can either use ContextActionService or create your own buttons. The only difference using those two is:

  • ContextActionService automatically provides you a button
  • ContextActionService lets you position the button, but you can’t resize it.

  • Creating your own button will let you have free control on the button’s properties. (Resize, position, color, etc.)

Oh thank you very much
But how to script the button that using Context Action Service

Hello me again, I have made the script into my gun using @varjoy comments for reference.
However, It doesn’t work. Can anyone help pls?

This is my gun:
https://www.roblox.com/library/5500173370/Assualt-Rifle-for-devforum

Notice that I have made changes on Line 76, 108-116
Thank you very much :smiley:

1 Like

1 Like

and if you want to add an Image Label ContextActionService:SetImage(“ReloadButton”,“http://www.roblox.come/asset/?id=1398003510”)


image

3 Likes