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

Context Action Service Help?

Asked by 5 years ago

i just need to know how to make a context action service replace the button Q, is that possible or will i have to bind it to the function?

1 answer

Log in to vote
1
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

For ContextActionService, this is what it should look like, I'm not too much of a wiz on this Service but I know enough to show an example, I most likely wont be able to provide a proper explanation, so please see https://developer.roblox.com/api-reference/class/ContextActionService for more information!

local ContextActionService = game:GetService("ContextActionService")
local Player = game:GetService("Players").LocalPlayer
local function ResetCharacter()
   local Character = Player.Character or Player.CharacterAdded:wait()
   local Head = Character:FindFirstChild("Head")
   if (Head) then
      Head:Destroy(); Wait(1); Player:LoadCharacter()
   end
end
ContextActionService:BindAction("ResetButton", ResetAvatar, true, Enum.KeyCode.R)
ContextActionService:SetPosition("ResetButton", UDim2.new(Vector2, Vector2))
ContextActionService:SetImage("ResetButton", "bxassetid")

Most Users prefer or recommend this Service over UserInputService, yet honestly, in my personal opinion, I wouldn't, I find it too confusing, I'll try to explain what's going on:

Most see above can be recognized as Indexing, and writing functions. That's exactly what it is no more. Except when it comes to :BindAction(), this is the first step, this BuiltInFunction has four arguments: (Reference name; variable, function; event that occurs when tapped, if the button should be functional or not; boolean, same event occur when "key" is pressed on computer). This ultimately sets up the Button, for those who don't understand what I mean by Button, ContextActionService is a Service built to make mobile devices compatible with computers. This Service creates a button similar to the Jump button seen on mobile devices.

After this, we have optional advancements, such as customary positioning, yet remember, the first argument always consists of the reference name. Then there's setting a customary Image for the Button, reading the arguments displayed should be pretty self-explanatory.

After this, let the Script run, make sure to test this whilst in Emulation mode.

Hope this helps you out if so, don't forget to Upvote and Accept this Answer!

0
use Enum.KeyCode.YOUR KEY yHasteeD 1819 — 5y
0
I believe, it should be shown in a String, but sure, I'll add the change Ziffixture 6913 — 5y
0
Also ...:wait() is deprecated use ...:Wait() yHasteeD 1819 — 5y
0
works perfectly fine Ziffixture 6913 — 5y
View all comments (5 more)
0
and :Remove() is deprecated, use :Destroy() see this: https://developer.roblox.com/api-reference/function/Instance/Remove yHasteeD 1819 — 5y
0
hm Ziffixture 6913 — 5y
0
Happy? Ziffixture 6913 — 5y
0
missed the :wait(), change to :Wait() line 04, after player.CharacterAdded yHasteeD 1819 — 5y
Ad

Answer this question