In my game, I have a serverscript in ServerScriptService that fires events based off when a player joins and leaves. For the purposes of my game, it first sets the player’s collision group and gives them a folder in workspace, and then once they leave, that folder is then removed.
(Each player has a folder that contains vehicles they may spawn.)
Problem is, it just stops working? I can’t determine when or how it stops working, because when a server initially begins it appears to be fine.
Just compare this image of the leaderboard to the explorer-menu I have up. There should only be 7 player folders in there ( not counting debris), not way more.
Here is the code:
local players = game:GetService(“Players”)
local function setPlayerCollisionGroup(character)
for _, part in character:GetChildren() do
if part:IsA(“BasePart”) then
part.CollisionGroup = “Players”
end
end
endplayers.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
setPlayerCollisionGroup(character)
local folder = Instance.new(“Folder”)
folder.Name = player.Name
folder.Parent = workspace:WaitForChild(“TrainFolder”)
end)
end)players.PlayerRemoving:Connect(function(player)
local targetFolder = workspace.TrainFolder:FindFirstChild(player.Name)
if targetFolder then
targetFolder:Destroy()
end
end)for _, player in players:GetPlayers() do
if player.Character then
setPlayerCollisionGroup(player.Character)
end
end
Any help is appreciated, thank you!
