Hi there.
I have a problem with collision groups. It doesn’t work as I would like.
When I do “PhysicsService:CollisionGroupSetCollidable(“playersTeam1”,“wall”, true)”, it doesn’t work.
However, the Editor shows that the collisions are triggered.
All parts used are CanCollide = true
If I change the CanCollide property of any part inside the character, it acts as a refresh and then it works.
Why doesn’t it work directly?
here is a video to show the problem:
script :
local PhysicsService = game:GetService("PhysicsService")
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAppearanceLoaded:Connect(function(char)
local hroot = char:WaitForChild("HumanoidRootPart")
local partCollide = Instance.new("Part")
partCollide.Name = "partCollide"
partCollide.Parent = char
partCollide.Size = Vector3.new(4,5.84,2)
partCollide.CFrame= hroot.CFrame
partCollide.Anchored = false
partCollide.Transparency = .5
local weld = Instance.new("WeldConstraint")
weld.Parent= partCollide
weld.Part0= partCollide
weld.Part1= hroot
PhysicsService:SetPartCollisionGroup(partCollide, "playersTeam1")
end)
end)
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
PhysicsService:CollisionGroupSetCollidable("playersTeam1","wall", true)
print("Collision Group True")
end)
LocalScript (in character)
local player = game.Players.LocalPlayer
local char = script.Parent
game.UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.P then
game.ReplicatedStorage.RemoteEvent:FireServer()
end
end)
I noticed some weird group collision behavior. When the character jumps the collisions change.
you can see it in this video.
new script
local PhysicsService = game:GetService("PhysicsService")
PhysicsService:CollisionGroupSetCollidable("playersTeam1","wall", false)
PhysicsService:CollisionGroupSetCollidable("Default","wall", false)
PhysicsService:CollisionGroupSetCollidable("Default","playersTeam1", false)
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAppearanceLoaded:Connect(function(char)
local hroot = char:WaitForChild("HumanoidRootPart")
local partCollide = Instance.new("Part")
partCollide.Name = "partCollide"
partCollide.Parent = char
partCollide.Size = Vector3.new(4,5.84,2)
partCollide.CFrame= hroot.CFrame
partCollide.Anchored = false
partCollide.Transparency = .5
local weld = Instance.new("WeldConstraint")
weld.Parent= partCollide
weld.Part0= partCollide
weld.Part1= hroot
PhysicsService:SetPartCollisionGroup(partCollide, "playersTeam1")
end)
end)
local db =true
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
if db then
PhysicsService:CollisionGroupSetCollidable("playersTeam1","wall", true)
print("Collision Group True")
player.Character.partCollide.BrickColor = BrickColor.new("Red flip/flop")
workspace.Wall.BrickColor = BrickColor.new("Red flip/flop")
else
PhysicsService:CollisionGroupSetCollidable("playersTeam1","wall", false)
print("Collision Group false")
player.Character.partCollide.BrickColor = BrickColor.new("Baby blue")
workspace.Wall.BrickColor = BrickColor.new("Baby blue")
end
db = not db
end)
Collision groups.rbxl (42,1 Ko)
I need help fast.
thank you.