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

How to make Context Action Service visible when a tool is equipped?

Asked by 2 years ago
Edited 2 years ago

Ok so I made a simple tool that's supposed to have a skill with it. Now I'm trying to make it have a skill button for mobile players that will only become visible and make it so that it only runs or functions properly when the tool is equipped. But I can't figure out how I'm supposed to do that. Can anyone help?

local CAS = game:GetService("ContextActionService")

function onButtonPress()
    local rand = math.random(1,3)
    local soundfx = script.Parent:WaitForChild("SoundFX") --folder of the sfx
    if rand == 1 then
        soundfx.Fart1:Play()
    else
        if rand == 2 then
            soundfx.fart2:Play()
        else
            if rand == 3 then
                soundfx.fart3:Play()
            end
        end
    end
end

local MB = CAS:BindAction("SkillButton",onButtonPress,true,"E") -- "E" for pc plrs
CAS:SetPosition("SkillButton",UDim2.new(0.603, 0,0.101, 0))
CAS:SetImage("SkillButton","http://www.roblox.com/asset/?id=585445238")
local SkillButton = CAS:GetButton("SkillButton")
SkillButton.Size = SkillButton.Size + UDim2.new(0, 20,0, 20)

Answer this question