How could I achieve getting something like a boat to be uncollidable with other boats?

local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvents = replicatedStorage:FindFirstChild("RemoteEvents")

local serverStorage = game:GetService("ServerStorage")
local serverScriptService = game:GetService("ServerScriptService")

local PhysicsService = game:GetService("PhysicsService")

local playerSetup = serverScriptService:FindFirstChild("PlayerSetup")
local modules = playerSetup.Modules

local logModule = modules.Log
local boatToSpawn

local isBoat

local GroupName = "BoatCollision"

PhysicsService:CreateCollisionGroup(GroupName)
PhysicsService:CollisionGroupSetCollidable(GroupName, GroupName, false)

local function SetCollisionGroup(Part)
	if Part:IsA("BasePart") or Part:IsA("Part") then
		PhysicsService:SetPartCollisionGroup(Part, "BoatCollision")
	end
end

remoteEvents.SpawnBoat.OnServerEvent:Connect(function(player)
	isBoat = workspace:FindFirstChild(player.Name .. " Boat")
	
	if isBoat then
		isBoat:Destroy()
	end
	
	boatToSpawn = serverStorage.Boat:Clone()
	boatToSpawn.Name = player.Name .. " Boat"
	
	for _,Object in pairs(boatToSpawn:GetChildren()) do
		SetCollisionGroup(Object)
	end
	
	boatToSpawn.Parent = workspace
end)

This is the code I’m using. I set CollisionGroups to hopefully prevent any other boats from colliding (basically like, they are CanCollide false so you cant just run them over)

This boat is 2-seated, so it’s not a local boat.

1 Like

few things I can think of

  1. you’re using GetChildren() which means that if some parts are in a model or a folder then they wont get added to the collision group, so try GetDescendants()
  2. The player’s character isn’t being added to the collision group so maybe somehow the player’s character hit’s the other boat?
  3. I bellive that you can’t use CollisionGroup on parts that are parented to nil, so parent the boat to the workspace first before handling collisiongroup? this may not be true so don’t take my word for it
1 Like