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
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:
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
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