How to set colllision group through local script

i have an error, where i need to set collision group through through a local script, however because of the physics service changes i have no idea how to use it. here is my script:

local PhysicsService = game:GetService("PhysicsService")
local ReplicateStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")

local towers = ReplicateStorage:WaitForChild("Towers")

local camera = workspace.CurrentCamera
local gui = script.Parent

local towerToSpawn = nil

local function MouseRaycast(blacklist)
	local mousePosition = UserInputService:GetMouseLocation()
	local mouseRay = camera:ViewportPointToRay(mousePosition.X, mousePosition.Y)
	local raycastParams = RaycastParams.new()
	
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
	raycastParams.FilterDescendantsInstances = blacklist
	
	local raycastResult = workspace:Raycast(mouseRay.Origin, mouseRay.Direction * 1000, raycastParams)
	
	
	return raycastResult
end

local function AddPlaceholderTower(name)
	
	local towerExists = towers:FindFirstChild(name)
	if towerExists then
		towerToSpawn = towerExists:Clone()
		towerToSpawn.Parent = workspace.Towers
		
		for i, object in ipairs(towerToSpawn:GetDescendants()) do
			if object:IsA("BasePart") then
				PhysicsService:CollisionGroupSetCollidable("Tower", "Tower", false)
				object. = "Tower"
			end
		end
	end
end

gui["main-game"].Frame.Frame.Spawn.Activated:Connect(function()
	AddPlaceholderTower("Pistol")
end)

UserInputService.InputBegan:Connect(function(input, processed)
	if processed then
		return
	end
	
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		
	end
end)

RunService.RenderStepped:Connect(function()
	if towerToSpawn then
		local result =  MouseRaycast({towerToSpawn})
		if result and result.Instance then
			local x = result.Position.X
			local y = result.Position.Y + towerToSpawn.Humanoid.HipHeight + (towerToSpawn.PrimaryPart.Size.Y / 2)
			local z = result.Position.Z

			local cFrame = CFrame.new(x,y,z)
			towerToSpawn:SetPrimaryPartCFrame(cFrame)
		end
	end
end)


this is the error:
This API can only be used on the server!

1 Like

you can just check all descendants of the tower and set all CanCollide to false.

i have tried that although idk why but it doesnt work
i just needa know how i set collision group through a local script

you cant, did you ever check the documentations, you can only use remotes

1 Like

“The only part of PhysicsService which is server-side is the ability to create and delete groups as well as modify the collision relationships between groups. LocalScripts are still able to set a part’s collision group for local collision filtering. So long as the server creates the groups, the client is good to go.”

1 Like