How to remove the colision between the enemy and the player?

I need to make it so that when the enemy attacked you, he did not hit from you, but just either stopped or passed through you, how to do it? That’s what I have right now:
Снимок экрана 2024-01-25 в 17.44.20

And I need to do so that it does not hit me like this, that is, I want to remove the coliseum, but I do not know how to do it, please advise me.

5 Likes

I’d work with Collision Groups to have players and npcs in 2 separate groups, then have those two groups unable to collide with each other

3 Likes

And can you give an example of how to do this, how to give players one colision “player” and monsters the second “monster” and make it so that they do not touch each other

2 Likes

Disabling Character Collisions explains how to set all parts of a player’s character to be in a collision group on spawn. For the NPCs, you could just set the collision group while you’re still in studio without scripts. Creating the two groups and adjusting them to not collide with each other can be done in studio too

2 Likes

Here is an example of how to do that in case you are still looking.

local PhysicsService = game:GetService("PhysicsService")

PhysicsService:RegisterCollisionGroup("Players")
PhysicsService:RegisterCollisionGroup("Npcs")

PhysicsService:CollisionGroupSetCollidable("Players", "Npcs", false)

--[[
If you want to avoid collisions between players or NPCs

PhysicsService:CollisonGroupSetCollidable("Players", "Players", false)
PhysicsService:CollisonGroupSetCollidable("Npcs", "Npcs", false)
]]

local function AddCharacterToCollisionGroup(Character, CollisionGroup)
	for Index, Part in Character:GetDescendants() do
		if not Part:IsA("BasePart") then continue end

		Part.CollisionGroup = CollisionGroup
	end
end

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		AddCharacterToCollisionGroup(Character, "Players")
	end)
end)
3 Likes

Ok I created a script in serverscriptService, and pasted your script there, but it doesn’t work, what else do I need to add to make it work?

local PhysicsService = game:GetService("PhysicsService")

PhysicsService:RegisterCollisionGroup("Players")
PhysicsService:RegisterCollisionGroup("Npcs")

PhysicsService:CollisionGroupSetCollidable("Players", "Npcs", false)

--[[
If you want to avoid collisions between players or NPCs

PhysicsService:CollisonGroupSetCollidable("Players", "Players", false)
PhysicsService:CollisonGroupSetCollidable("Npcs", "Npcs", false)
]]

local function AddCharacterToCollisionGroup(Character, CollisionGroup)
	for Index, Part in Character:GetDescendants() do
		if not Part:IsA("BasePart") then continue end

		Part.CollisionGroup = CollisionGroup
	end
end

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		AddCharacterToCollisionGroup(Character, "Players")
	end)
end)
2 Likes

Sorry for the delay, you need to add the NPCs to the collision group. Do you have a folder that stores the NPCs in your workspace?

2 Likes

Yeah, I can make a folder where I put all the model npcs.

1 Like

ok, you just need to add the characters to collision group at the beginning of the game and when they are added to the folder.

local PhysicsService = game:GetService("PhysicsService")

PhysicsService:RegisterCollisionGroup("Players")
PhysicsService:RegisterCollisionGroup("Npcs")

PhysicsService:CollisionGroupSetCollidable("Players", "Npcs", false)

local NpcsFolder = workspace.Npcs -- Npcs folder 

--[[
If you want to avoid collisions between players or NPCs

PhysicsService:CollisonGroupSetCollidable("Players", "Players", false)
PhysicsService:CollisonGroupSetCollidable("Npcs", "Npcs", false)
]]

local function AddCharacterToCollisionGroup(Character, CollisionGroup)
	for Index, Part in Character:GetDescendants() do
		if not Part:IsA("BasePart") then continue end

		Part.CollisionGroup = CollisionGroup
	end
end

for Index, Npc in NpcsFolder:GetChildren() do
	AddCharacterToCollisionGroup(Npc, "Npcs")
end

NpcsFolder.ChildAdded:Connect(function(newNpc)
	AddCharacterToCollisionGroup(newNpc, "Npcs")
end)

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		AddCharacterToCollisionGroup(Character, "Players")
	end)
end)
2 Likes

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