Hello!
I’m working on a game placement mode which allows you to place objects and cancel object placement. I’m trying to use ContextActionService, however the function seems not to bind, as no input affects anything. I’ve added a print and that doesn’t do anything either.
The actual function:
local function buildMode(actionName, key, inputObject)
if actionName == 'buildMode' then
if key.UserInputType == Enum.UserInputType.MouseButton1 then
local canPlace
local s,e = pcall(function()
canPlace = Functions.PurchaseObject:InvokeServer(Selection.PrimaryPart.CFrame)
end)
if not s then return end
if canPlace == true then
print('canPlace')
return
end
elseif key.UserInputType == Enum.UserInputType.Keyboard then
if key.KeyCode == Enum.KeyCode.R then
PlacementModule:Rotate(Mouse, Selection)
end
end
end
end
What should bind and unbind the action
btn.MouseButton1Click:Connect(function()
local SelectionRS = game.ReplicatedStorage.Models.PlotModels[Model.Name]
Selection = SelectionRS:Clone()
if not Selection.PrimaryPart then
Selection.PrimaryPart = Selection:FindFirstChild('BoundingBox')
end
local canPlace = Functions.RequestCanPlace:InvokeServer(SelectionRS)
Mouse.Move:Connect(function()
PlacementModule:SnapToGrid(Mouse, Selection, false)
end)
CAS:BindAction('buildMode', buildMode, false)
UIS.InputBegan:Connect(function(key, isSystemReserved)
if key.KeyCode == Enum.KeyCode.Q then
CAS:UnbindAction('buildMode')
end
end)
end)