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

ContextActionService error with CoreGui ?

Asked by 8 years ago

Hello, I wanted to familiarize a little more with ContextActionService to make my game more mobile friendly. I wanted to make button that whenever is held, it fires in a weapon, and when the player stops holding the button, it stops firing. I tried it in a test place and everything worked fine. So I moved the script that manages all of this to my game, but now, I get an error every time I try to bind the action. Here's a screenshot of what the errors look like: http://imgur.com/a/ZptkO

The script I use is exactly the same in both places.

Here's my code (which is obviously in a local script):

if not game:GetService("UserInputService").KeyboardEnabled then

local ContextAction = game:GetService("ContextActionService")
local EquippedTool = nil

local Fire = function(ActionName, ActionInputState)
    if ActionInputState == Enum.UserInputState.Begin then
        require(EquippedTool.Fire).Button1Down(EquippedTool.Parent.Humanoid.TargetPoint)
    elseif ActionInputState == Enum.UserInputState.End then
        require(EquippedTool.Fire).Button1Up()
    end
end

ContextAction.LocalToolEquipped:Connect(function(Tool)
    if Tool:FindFirstChild("Fire") then
        EquippedTool = Tool
        ContextAction:BindAction("Fire",Fire,true,Enum.UserInputType.MouseButton1)
        ContextAction:SetPosition("Fire",UDim2.new(1,-135,1,-75)) 
        ContextAction:SetImage("Fire","http://www.roblox.com/asset/?id=541371647")
    end
end)

ContextAction.LocalToolUnequipped:Connect(function(Tool)
    if Tool:FindFirstChild("Fire") then
        ContextAction:UnbindAction("Fire")
        EquippedTool = nil
    end
end)

end

I think my code is correct, but let me know ! Thanks

Answer this question