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?
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!