Hi! I’m making a tower defence game and players can’t collide with other players, monsters or towers. Only in studio. As soon as I get teleported into the game from the lobby, I can suddenly collide with towers and monsters. Sometimes I don’t collide while my friends do and sometimes I do too.
I have a script for the players, mobs and towers. I’ll only send the CollisionGroup part of the script:
Mobs:
for i, object in ipairs(newmob:GetDescendants()) do
if object:IsA("BasePart") then
object.CollisionGroup = "Mob"
end
end
Players:
player.CharacterAdded:Connect(function(char)
for i, object in ipairs(char:GetDescendants()) do
if object:IsA("BasePart") then
object.CollisionGroup = "Player"
print(object.CollisionGroup)
end
end
end)
Towers:
for i, object in ipairs(newtower:GetDescendants()) do
if object:IsA("BasePart") then
object.CollisionGroup = "Tower"
end
end
player.CharacterAdded:Connect(function(char)
function NoCollide(object)
if object:IsA("BasePart") then
object.CollisionGroup = "Player"
print(object.CollisionGroup)
end
end
char.DescendantAdded:Connect(NoCollide)
for i, object in ipairs(char:GetDescendants()) do
task.spawn(NoCollide,object)
end
end)
Are these local scripts or server scripts.
Typically if something works in Studio and not in game it’s because in Studio your computer is running all the server scripts as well as the local scripts. In game the actual server is running the server scripts and your computer is running local scripts.
Update: The collision group works for me in game but as soon as my friends test they collide with other things. I tried printing their HumanoidRootPart’s collision group and that returned as Player. This makes no sense. I’m still looking for help
This doesn’t work for me, “NoCollide” comes out with an orange line, but it worked for me by putting “local” after “function”, other than that, thanks to you now the collisions in my game work very well