What do you want to achieve? Keep it simple and clear!
I want the NPC be unable to push by players.
What is the issue? Include screenshots / videos if possible!
The collision doesn’t work.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I looked at a few posts about this, but none of those helped me out. And yeah, I looked at it but could not find something useful.
Here Is the code I made, It’s In server script service.
local PysicsService = game:GetService("PhysicsService")
local PLAYER_CG = PysicsService:CreateCollisionGroup("PLAYERS")
local TARGET_CG = PysicsService:CreateCollisionGroup("TARGETS")
PysicsService:CollisionGroupSetCollidable("PLAYERS", "Default", true)
PysicsService:CollisionGroupSetCollidable("PLAYERS", "PLAYERS", false)
PysicsService:CollisionGroupSetCollidable("PLAYERS", "TARGETS", false)
PysicsService:CollisionGroupSetCollidable("TARGETS", "TARGETS", false)
PysicsService:CollisionGroupSetCollidable("TARGETS", "Default", true)
local function setCG(char,id)
for i, v in pairs(char:GetChildren()) do
if v:IsA("BasePart") or v:IsA("Part") then
v.CollisionGroupId = id
print(v)
end
end
end
for i, v in pairs(workspace.TargetFolder:GetChildren()) do
setCG(v, "TARGETS")
end
workspace.PlayerFolder.ChildAdded:Connect(function(c)
setCG(c,"PLAYERS")
end)
workspace.TargetFolder.ChildAdded:Connect(function(c)
setCG(c,"TARGETS")
end)
for i, v in pairs(game.Players:GetPlayers()) do
setCG(v, "PLAYERS")
end
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function()
print("Character found.")
setCG(Player.Character, "PLAYERS")
end)
end)
It prints out “Character found.” and the every single part in the model found by the way.
Well, As I saw from the other posts, some player acctually did it with the string. I also tried out SetPartCollisionGroup() too, but it didn’t also work.
Hello again. So I’ve tried what you’ve said, the updated code is
local PysicsService = game:GetService("PhysicsService")
PysicsService:CollisionGroupSetCollidable("PLAYERS", "Default", true)
PysicsService:CollisionGroupSetCollidable("PLAYERS", "TARGETS", false)
PysicsService:CollisionGroupSetCollidable("TARGETS", "TARGETS", false)
PysicsService:CollisionGroupSetCollidable("TARGETS", "Default", true)
local function set_CG(char,id)
for i, v in pairs(char:GetChildren()) do
if v:IsA("BasePart") or v:IsA("Part") then
PysicsService:SetPartCollisionGroup(v, id)
end
end
end
for i, v in pairs(workspace.TargetFolder:GetChildren()) do
set_CG(v, "TARGETS")
end
workspace.PlayerFolder.ChildAdded:Connect(function(c)
set_CG(c,"PLAYERS")
end)
workspace.TargetFolder.ChildAdded:Connect(function(c)
set_CG(c,"TARGETS")
end)
for i, v in pairs(game.Players:GetPlayers()) do
set_CG(v, "PLAYERS")
end
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function()
print("ok char")
set_CG(Player.Character, "PLAYERS")
Player.Character.Parent = workspace:WaitForChild("PlayerFolder")
end)
end)
I deleted the CreateCollisionGroup() from the top and tried it in Collision Groups tab. I also did the thing you said. It still gave no error but it doesn’t also worked as well.
Hello, sorry I am late but that also didn’t work as well. I am willing to give you more information about this.
So, There’s 2 folders in workspace, “PlayerFolder” and “TargetFolder”.
The NPC’s go in TargetFolder. And the Players go in the PlayerFolder.
The NPC’s are like this. They are kinda small. All I want is to make is that it is pushable by other players.
The current script is:
local PysicsService = game:GetService("PhysicsService")
PysicsService:CollisionGroupSetCollidable("PLAYERS", "Default", true)
PysicsService:CollisionGroupSetCollidable("PLAYERS", "TARGETS", false)
PysicsService:CollisionGroupSetCollidable("TARGETS", "TARGETS", false)
PysicsService:CollisionGroupSetCollidable("TARGETS", "Default", true)
local function set_CG(char,id)
for i, v in pairs(char:GetDescendants()) do
if v:IsA("BasePart") or v:IsA("Part") then
PysicsService:SetPartCollisionGroup(v, id)
end
end
end
for i, v in pairs(workspace.TargetFolder:GetChildren()) do
set_CG(v, "TARGETS")
end
workspace.PlayerFolder.ChildAdded:Connect(function(c)
set_CG(c,"PLAYERS")
end)
workspace.TargetFolder.ChildAdded:Connect(function(c)
set_CG(c,"TARGETS")
end)
for i, v in pairs(game.Players:GetPlayers()) do
set_CG(v, "PLAYERS")
end
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function()
print("ok char")
set_CG(Player.Character, "PLAYERS")
Player.Character.Parent = workspace:WaitForChild("PlayerFolder")
end)
end)
PysicsService:CollisionGroupSetCollidable("PLAYERS", "Default", true)
PysicsService:CollisionGroupSetCollidable("PLAYERS", "TARGETS", false)
PysicsService:CollisionGroupSetCollidable("TARGETS", "PLAYERS", false)
PysicsService:CollisionGroupSetCollidable("TARGETS", "TARGETS", false)
PysicsService:CollisionGroupSetCollidable("TARGETS", "Default", true)