-
I am trying to make a script so players and zombies don’t collide with each other
-
Help whit NPC don't collide whit player. - YouTube
As you can see in this clip, the zombies don’t collide with each other but they collide whit the player.
-
I have used a part of script form this post:How to make npcs and players not collide
and it seams to be this part(wich is supposed to give the players the collision group) that does not work because when i look at the part in the player, they don’t seem to have changed collision group.
This is my script:
local physicsService = game:GetService("PhysicsService")
local zombieFolder = game.Workspace:WaitForChild("Zombies").Zombie
local zombieTable = zombieFolder:GetChildren()
local zombiePartTable
function zombieInGroup()
for i, v in pairs(zombieTable) do
if tostring(v) == "Zombie" then
zombiePartTable = zombieTable[i]:GetChildren()
for index, value in pairs(zombiePartTable) do
if value:IsA("BasePart") then
physicsService:SetPartCollisionGroup(zombiePartTable[index], "Zombie")
end
end
end
end
end
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
Character:WaitForChild("HumanoidRootPart")
Character:WaitForChild("Head")
Character:WaitForChild("Humanoid")
for i,v in pairs(Character:GetDescendants()) do
if v:IsA("BasePart") then
physicsService:SetPartCollisionGroup(v,"Player")
print("setGroup")
end
end
end)
end)
physicsService:CreateCollisionGroup("Zombie")
physicsService:CreateCollisionGroup("Player")
physicsService:CollisionGroupSetCollidable("Zombie", "Player", false)
physicsService:CollisionGroupSetCollidable("Zombie", "Zombie", false)
zombieInGroup()
1 Like
Make both the zombies and players have the same collision group.
You can probably name the collsiongroup “Humanoids” to make it easier to understand.
When the player joins the game and character spawns, on character spawn, set the character to the “Humanoids” collisiongroup.
For the zombies, if you spawn them, set it the same way and make sure the name is the same.
If its in studio/you’re just ctrl + d ing the zombies, you can use the collisiongroupeditor to make life easier.
I don’t think its neccessary to have different collision groups for both zombies and humanoids but if required then you can just have small adjustments in the editor/values.
I just tried to do the same collision group but it does not seem to work. I think the problem is that the player is not getting the collision group because when i go look in it’s parts, the collision group ID is still 0
Ok i figured it out, i actually use this code:
local physicsService = game:GetService("PhysicsService")
local zombieFolder = game.Workspace:WaitForChild("Zombies").Zombie
local zombieTable = zombieFolder:GetChildren()
physicsService:CreateCollisionGroup("Humanoid")
physicsService:CreateCollisionGroup("Player")
--physicsService:CollisionGroupSetCollidable("Zombie", "Player", false)
physicsService:CollisionGroupSetCollidable("Humanoid", "Humanoid", false)
local zombiePartTable
function zombieInGroup()
for i, v in pairs(zombieTable) do
zombiePartTable = zombieTable[i]:GetChildren()
for index, value in pairs(zombiePartTable) do
if value:IsA("BasePart") then
physicsService:SetPartCollisionGroup(zombiePartTable[index], "Humanoid")
end
end
end
end
local playerPartTable
game.Players.PlayerAdded:Connect(function(plr)
playerPartTable = game.Workspace:WaitForChild(plr.name):GetChildren()
for i, v in pairs(playerPartTable) do
if v:IsA("BasePart") then
physicsService:SetPartCollisionGroup(playerPartTable[i], "Humanoid")
print("fait")
end
end
end)
zombieInGroup()