The Collision Script is not working. I have no idea why. anyhelp?
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
for i, object in ipairs(character:GetDescendants()) do
if object:IsA(“BasePart”) then
object.CollisionGroup = “Player”
end
end
end)
end)
end) –
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
for i, object in ipairs(character:GetDescendants()) do
if object:IsA(“BasePart”) then
object.CollisionGroup = tostring(player.UserId) – use a unique value
end
end
end)
end)
-- [Variables] --
local Players = game:GetService("Players")
-- [Script] --
local function AddCharacter(Character:Model)
for _, Object in ipairs(Character:GetDescendants()) do
if (Object:IsA("BasePart") == true) then
Object.CollisionGroup = "Player"
end
end
end
local function AddPlayer(Player : Player)
AddCharacter(
if (Player.Character ~= nil) then
Player.Character
else
Player.CharacterAdded:Wait()
)
Player.CharacterAdded:Connect(AddCharacter)
end
for _, Player in ipairs(Players:GetPlayers()) do
task.spawn(AddPlayer, Player)
end
Players.PlayerAdded:Connect(AddPlayer)
The problem was that players may have been added before you connected the .PlayerAdded event. The same also applies to the .CharacterAdded event, the players character may have loaded before you connected .CharacterAdded event.
I tested the script and it worked for me so maybe the script isn’t running? Maybe put a print statement at the start of the script and see if it prints?
Maybe it could be somethings overwriting the collision group? Try this script and see if it warns anything.
-- [Variables] --
local Players = game:GetService("Players")
-- [Script] --
local function AddCharacter(Character:Model)
for _, Object : BasePart in ipairs(Character:GetDescendants()) do
if (Object:IsA("BasePart") == true) then
Object.CollisionGroup = "Player"
print(Object.CollisionGroup)
Object.Changed:Connect(function(Property)
if (Property == "CollisionGroup") then
warn(Object.CollisionGroup)
end
end)
end
end
end
local function AddPlayer(Player : Player)
AddCharacter(
if (Player.Character ~= nil) then
Player.Character
else
Player.CharacterAdded:Wait()
)
Player.CharacterAdded:Connect(AddCharacter)
end
for _, Player in ipairs(Players:GetPlayers()) do
task.spawn(AddPlayer, Player)
end
Players.PlayerAdded:Connect(AddPlayer)
I would try that(using a local server) because I noticed some other CollisionGroups and those may not be working correctly, you can always check the CollisionGroup property in the properties which may help.