CollisionGroup doesnt work?

Hello there!

I am making a tower defense game, but the collisiongroups arent working. I have no idea why, because no errors or warnings pop up. I have also checked the Collison Group Editor for errors.

Here is the script:

for i, object in ipairs(newTower:GetDescendants()) do
			if object:IsA("BasePart") then
				object.CollisionGroup = "Tower"
			end
		end

Have a good day! :wink:

What do you mean they “aren’t working”? Is the CollisionGroup property not being set? Are the towers colliding with things they shouldn’t? If the latter is the case, then you probably just configured the collision group improperly (I suggest reading this article if you’re new to them)

I have read the article before. The issue is: I can still collide with the towers. I have checked multiple times and I think I configured the group corrrectly. Here is a screenshot:
image

It’s possible that the collision group settings for the “Tower” group are not configured properly in the Collision Group Editor.

To check if the CollisionGroup property is set correctly, you can add a print statement to the loop to output the CollisionGroup property of each BasePart object:


for i, object in ipairs(newTower:GetDescendants()) do
    if object:IsA("BasePart") then
        object.CollisionGroup = "Tower"
        print(object.Name, object.CollisionGroup)
    end
end

Have you set the player’s body-parts to have the Player collision group then? I’ve forgotten to do that before which caused me a world of trouble

I have right here:

for i, object in ipairs(player:GetDescendants()) do
		if object:IsA("BasePart") then
			object.CollisionGroup = "Player"
		end
	end

It’s printing the object name, but it’s not printing the collision group…

Oh my god. I’m so sorry for being so stupid. I forgot to add:

player.CharacterAdded:Connect(function(character)

That’s the reason it wasnt working!

player.CharacterAdded:Connect(function(character)
	for i, object in ipairs(character:GetDescendants()) do
		if object:IsA("BasePart") then
			object.CollisionGroup = "Player"
		end
	end

But thank you for the help :smiling_face:

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