Collision group script not working

I made a collision group script for my Tower Defence (TD) game and I’m struggling to make the script work.

When I run the game I get an error message saying “Parameter 1 must be BasePart in SetPartCollisionGroup.” and the enemies don’t spawn or move either.

May someone please help me because I really want to release this game before April 25th 2023.

Here is the script I used:

Script: (Module Script Parent)

local mob = require(script.Mob)
local map = workspace.LumberjackVillage

for i=1, 5 do -- WAVE 1
	mob.Spawn("Normal", map)
	task.wait(0.5)
end
for i=1, 5 do -- WAVE 2
	mob.Spawn("Speedy", map)
	task.wait(0.5)
end
for i=1, 5 do -- WAVE 3
	mob.Spawn("Slow", map)
	task.wait(0.5)
end

Module Script: (For Functions)

local PhysicsService = game:GetService("PhysicsService")
local ServerStorage = game:GetService("ServerStorage")
local mob = {}

function mob.Move(mob, map)
	local humanoid = mob:WaitForChild("Humanoid")
	local waypoints = map.Waypoints
	
	for waypoint=1, #waypoints:GetChildren() do
		humanoid:MoveTo(waypoints[waypoint].Position)
		humanoid.MoveToFinished:Wait()
	end
	
	mob:Destroy()
	
end

function mob.Spawn(name, map)
	local mobExists = ServerStorage.Mobs:FindFirstChild(name)
	
	if mobExists then
		local newMob= mobExists:Clone()
		newMob.Parent = workspace
		
		for i, object in ipairs(newMob:GetDescendants()) do
			if object:IsA("BasePart") then
				PhysicsService:SetPartCollisionGroup(newMob, "Mob")
			end
		end
		
		
		coroutine.wrap(mob.Move)(newMob, map)
	else
		warn("Requested mob does not exist:", name)
	end
end

return mob

I think you are supposed to put object instead of the model


for i, object in ipairs(newMob:GetDescendants()) do
	if object:IsA("BasePart") then
		PhysicsService:SetPartCollisionGroup(object, "Mob")
	end
end
1 Like

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