Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Correct Syntax for ContextActionService?

I only slightly know what I'm doing with this, the Roblox Wiki didn't explain much. So, I'm trying to have a detection for when the mouse is moved, Left Mouse button is down, The Player Name matched a value, AND the part they are touching matches a specified name. I've experimented with different methods & events but they all proved too laggy or impractical.

Back to the point though, anyone with knowledge regarding ContextActionService care to help me out? Something isn't working here, but I don't know what it is. I have narrowed down the location of the error/broken code to either Lines 6, 7, or 17.

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Leader = workspace.Leader.Value 

Mouse.Move:connect(function()
	function Detonate(actionName, userInputState, inputObject)
		if userInputState == Enum.UserInputState.Begin then
			print("Input State Works!")
			local Target = Mouse.Target
			if Target then 
				if Player.Name == Leader and Target.Name == "button" then
					DetonateFunction() -- Function located elsewhere in script, not mentioned here.
				end
			end
		end

	game.ContextActionService:BindAction("Detonate", Detonate, false, Enum.UserInputType.MouseButton1)     
	end
end)

Line 12 does reference a function located elsewhere in the script, but I left it out since it doesn't share any variables/objects/etc with the code I have listed above. Any help is appreciated. Thanks! :)

EDIT: I am fairly certain is has something do with the way I laid out the syntax, hence the title. But as I said before I don't have any experience using ContextActionService so I'm not entirely sure. Just wanted to clarify.

EDIT 2: Just realized its ContextActionService, not BindAction. I think. Changed everything, but my question still stands.

2 comments

0

I have no time to post now, but I would recommend trying UserInputService instead. It is much easier to learn and works better for things like this.

0

Alright, I'll check it out. Thanks!

1 answer

No u have everything correct except you are forgetting the main part of CAS

local contextAction = Game:GetService("ContextActionService")--always put this first

This discussion is preserved as it was. New answers, comments, and votes are closed.