ContextActionService causing mobile players to stop moving

  1. I’m trying to make a base editing system where you can select and edit conveyors

  2. For some reason, when I don’t tap on a conveyor, or if I tap on the “Remove” button it stops me from moving(on mobile)

  3. I’m pretty sure this is because of the functions not returning Enum.ContextActionResult.Pass but it seems that all of the functions are so I dont know why this is happening.

I think it might be because of rebinding the actions in editor.Enable but im not sure

focusMode:

local function focusMode(_, inputState : Enum.UserInputState)
	if inputState ~= Enum.UserInputState.End then return Enum.ContextActionResult.Pass end
	if hovering then cleanup() end
	local result = cast()
	if result and result.Instance then
		local model = result.Instance:FindFirstAncestorOfClass("Model")
		if model then
			hovering = model:HasTag("Upgrade") and model or nil
			selectionBox.Adornee = model
			selectionBox.Parent = model
		end
	else
		hovering = nil
	end

	if not hovering then 
		editor.Enable()
		return Enum.ContextActionResult.Pass
	end

	local sucess, msg = pcall(function()
		if currentOptions then currentOptions:Destroy() end
		local modelCenter = GetModelCenter(hovering) + Vector3.new(0, 1, 0)
		currentOptions = buildOptions:Clone()
		billboardOptions = currentOptions.BuildOptions
		currentOptions.Parent = hovering
		currentOptions.Position = modelCenter
		selectionBox.Adornee = hovering
		currentOptions.Parent = hovering
		billboardOptions.Parent = player.PlayerGui
		billboardOptions.Adornee = currentOptions
		global.Editing = hovering
		upgradeConnection = billboardOptions.Upgrade.Activated:Connect(function()
			initUpgrade(nil, Enum.UserInputState.End)
		end)
		removeConnection = billboardOptions.Sell.Activated:Connect(function()
			removeFunc(nil, Enum.UserInputState.End)
		end)
		RunService:UnbindFromRenderStep(RENDER_ACTION)
		ContextActionService:UnbindAction(UPGRADE_ACTION)
		ContextActionService:BindAction(UPGRADE_ACTION, initUpgrade, false, Enum.KeyCode.Q) 
		ContextActionService:BindAction(REMOVE_ACTION, removeFunc, false, Enum.KeyCode.R)
	end)
	if not sucess then
		warn(debug.traceback(msg))
	end
	return Enum.ContextActionResult.Pass
end

removeFunc:

local function removeFunc(_, inputState : Enum.UserInputState)
	if inputState ~= Enum.UserInputState.End or not hovering then return end
	local sucess, msg = pcall(function()
		global.EditorEvent:FireServer(
			hovering:GetAttribute("Category"), 
			removeValues[hovering:GetAttribute("Category")], 
			global.Editing
		)
		editor.Enable()
	end)
	if not sucess then warn(msg) end
	return Enum.ContextActionResult.Pass
end
function editor.Enable()
	cleanup()
	unbindAll()
	RunService:BindToRenderStep(RENDER_ACTION, Enum.RenderPriority.Camera.Value, selectionMode)
	ContextActionService:BindAction(FOCUS_ACTION, focusMode, true, Enum.UserInputType.MouseButton1, Enum.UserInputType.Touch)
end

You don’t return Enum.ContextActionResult.Pass in your guard clause for removeFunc. This should hopefully fix the problem you’re having.

1 Like

That fixed the stuff with the remove button but the problem still happens when I dont tap on a conveyor(if I tap on the baseplate or the sky or anything NOT tagged “conveyor”)

I’m just guessing here but, I wonder if it’s because you’re calling unbindAll prior to returning the ContextActionResult. What does this function do?

unbind all unbinds all the runservice and contextactionservice bindings. But I removed the unbindall and replaced it with just unbinding what was necessary and it works now

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.