Hello fellow developers ! I want to create a context action service button which will have the value of keyboard input and by this I mean that the button which I ant to create should do the same thing as when right click or button2 is pressed on a keyboard. I would really appreciate any help I receive related to this topic.
I would suggest reading this article(if you scroll all the way down there is a code sample that is explained in depth ContextActionService (roblox.com)
Thank you very much ! This article helped me a lot but I didn’t understand this particular line of code can you please help me with this.
local function handleAction(actionName, inputState, inputObject)
that will create a function for binding an action. once that function is created, you can bind that function into action, with ContextActionService.
so far I have created this script but its not working , I don’t know why but there are no errors as well.
local contextactionservice = game:Getservice("ContextActionService")
local tool = script.Parent
local Block = "Block"
local function onButton2Press()
Block:Play()
end
tool.Equipped:Connect(function ()
contextactionservice:BindAction("Block" , onButton2Press , true , "Button2")
end)
tool.Unequipped:Connect(function ()
contextactionservice:UnbindAction(Block)
end)
here , block is an animation which is present inside the tool and I want it plays whenever the player presses right click while holding the tool and I want that same thing to happen when mobile players press the context action service button.
there is no function :Play()
for a string.
it is an animation inside the tool so what function should I use to play it?
local anim = tool.YourAnimName
local function onButton2Press()
anim:Play()
end
the context action service button is not being created for the player
what do you mean? is it an error?
there are no errors coming but the context action service button is not being created for the player. I launched an emulation for an iPad but there is no button to be found on the screen after equipping the tool.
maybe, you need to positioning it.
here , I did some recording of what is happening.
show me your full script. I wanna see what’s going on.
should I send the link of the model only ? I have no problem in publishing it for copying because the script is a little too big.
just show me a little bit. modify it so that it didn’t looked like your script. for example for swinging, you just change it to print(“SWING!”)
here. ClientScript - Roblox
its just the client script of the model where all the variables and normal functions as well as the attack script is present.
Theres this specific line which I think is creating the whole problem.
if stats.controls.lower then
contextActionService:BindAction(
"Lower",
LowerGun,
true,
stats.controls.lower
)
end
end)
tool.Unequipped:connect(function()
button1Down = false
mouse.Icon = ""
your LowerGun function doesn’t even do anything. that’s why it didn’t worked.
only
if inputState == Enum.UserInputState.Begin then
which is not doing anything
so I should just delete it ? I just yoinked it from some website.
no, you just need to make your function do something.