AMX13F3AM
(Amx_Dev)
August 4, 2020, 2:50am
#1
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
varjoy
(variable)
August 4, 2020, 2:58am
#3
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?
varjoy
(variable)
August 4, 2020, 3:02am
#5
:BindAction() is really simple, it automatically creates a button!
AMX13F3AM
(Amx_Dev)
August 4, 2020, 3:02am
#6
I tried the to use the text button but it didnt work
AMX13F3AM
(Amx_Dev)
August 4, 2020, 3:03am
#7
Oh really but im sorry that I dont have a deep knowledge about :BindAction()
roboxegor
(Disidente)
August 4, 2020, 3:03am
#8
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?
varjoy
(variable)
August 4, 2020, 3:06am
#15
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
AMX13F3AM
(Amx_Dev)
August 4, 2020, 3:07am
#17
Where to put this script? 30charrssssssss
You’ll need to use ContextActionService
here is a link to the Developer Hub:
AMX13F3AM
(Amx_Dev)
August 4, 2020, 3:08am
#19
We just talked about it
They tell me to browse it
AMX13F3AM
(Amx_Dev)
August 4, 2020, 3:15am
#20
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.
varjoy:
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)
2 Likes
AMX13F3AM
(Amx_Dev)
August 4, 2020, 3:24am
#22
I’m sorry I got to go
I will reply you as soon as possible
Quwanterz
(Quwanterz)
August 4, 2020, 4:54am
#23
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.)
AMX13F3AM
(Amx_Dev)
August 4, 2020, 6:01am
#24
Oh thank you very much
But how to script the button that using Context Action Service
AMX13F3AM
(Amx_Dev)
August 5, 2020, 2:18am
#25
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
1 Like
and if you want to add an Image Label ContextActionService:SetImage(“ReloadButton”,“http://www.roblox.come/asset/?id=1398003510 ”)
2 Likes