Context Action Service

I’m using Context Action Service, for an event when the player clicks, it fires two times, once when they click, and once when they release it. How can I stop it? I only want it to fire once.

local cas = game:GetService("ContextActionService")
local mouse = game.Players.LocalPlayer:GetMouse()

function FirePlacement()
	print("clicked!!")
	if mouse.Target == nil then
		return
	end
game.ReplicatedStorage.RemoteEvents.PlaceEvent:FireServer(mouse.Hit.p,mouse.TargetSurface)
end

cas:BindAction("BoundAction",FirePlacement,false,Enum.UserInputType.MouseButton1)

Check the input state.

local cas = game:GetService("ContextActionService")
local mouse = game.Players.LocalPlayer:GetMouse()

function FirePlacement(actionName, userInputState)
    if (userInputState ~= Enum.UserInputState.Begin) then return; end
	print("clicked!!")
	if mouse.Target == nil then
		return
	end
    game.ReplicatedStorage.RemoteEvents.PlaceEvent:FireServer(mouse.Hit.p,mouse.TargetSurface)
end

cas:BindAction("BoundAction",FirePlacement,false,Enum.UserInputType.MouseButton1)
6 Likes