Help with ContextActionService Firing Function

Im trying to use ContextActionService, But when I bind the action, the Function it is connected to fires, even if nothing is touched?
Am I using cas wrong? How do i Stop it from firing the function when binded?

function ActivateCAS()
	print("yip yahoo")
end

function FindClose()
	local FoundEnemy = false
	for i, v in pairs(workspace:GetChildren()) do
		if v:IsA("Model") then
			local RootPart = v:FindFirstChild("HumanoidRootPart",1)
			if Player:DistanceFromCharacter(RootPart.Position) < Distance then
				if v.Name ~= Player.Name then
				-----------------------
				FoundEnemy = true
				table.remove(TargetModule,1)
				table.insert(TargetModule,1,v)
				GUI.Parent = RootPart
				CAS:BindAction(Text, ActivateCAS, true, Enum.KeyCode.E)
				break
				-----------------------
				end
			end
		end
	end
	if FoundEnemy == false then
		GUI.Parent = game.ReplicatedStorage
		table.remove(TargetModule,1)
		CAS:UnbindAction(Text)
	end
end

UIS.TouchStarted:Connect(function(input)
	repeat
	wait(0.1)
	FindClose()
	until input.UserInputState == Enum.UserInputState.End
end)

Try changing your ActivateCAS() function to this:

function ActivateCAS(Action, State, Input)
    if Action == Text and State == Enum.UserInputState.Begin then
	    print("yip yahoo")
    end
end
1 Like