I am trying to make a script that is a join and leave system. It is kind of hard to explain it, but I will give you an example.
Example:
The first player (Player 1) comes up to this clickable part and clicks it. The button gave the one who clicked it an animation then stops right after. Once the animation reaches about half way, a part inside the model of the clickable part which is above it, will glow (Change colours) Then another player comes up and clicks it (Player 2), it does the same animation and the same thing happens. Above the first players glowing part, for player 2 it makes the part a different colour also above player 1’s colour part. But Player 1/Player 2 leaves, so then the top colour part will go down 1. This continues until there are 5 players max.
In these images you can see what I am trying to say:
And I also need a part that makes the cancolide on if you are not in the match.
Here is the script I have so far: (I am somewhat new to scripting)
local clickDetector = script.Parent
local Players = game:GetService("Players")
local model = clickDetector.Parent.Parent
local playerParts = {}
for _, child in model:GetChildren() do
if child:IsA("Part") and tonumber(child.Name:match("%d+")) then
table.insert(playerParts, child)
end
end
local clickCount = {}
local isAnimating = false
local function updateGlowState(player)
local color = Color3.fromHSV(0.6, 1, 1)
for _, part in playerParts do
part.Color = color
end
clickCount[player] = (clickCount[player] or 0) + 1
end
local function onClick(player)
if clickCount[player] and clickCount[player] > 0 then return end
clickCount[player] = 1
isAnimating = true
local humanoid = player.Character and player.Character:FindFirstChild("Humanoid")
if humanoid then
local animator = humanoid:FindFirstChild("Animator")
if animator then
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://140413569393737"
local track = animator:LoadAnimation(animation)
track:Play()
wait(2)
track:Stop()
isAnimating = false
updateGlowState(player)
end
end
end
local function onPlayerLeave(player)
clickCount[player] = nil
if next(clickCount) == nil then
for _, part in playerParts do
part.Color = Color3.new(0, 0, 0)
end
end
end
clickDetector.MouseClick:Connect(function(player)
onClick(player)
end)
Players.PlayerRemoving:Connect(function(player)
onPlayerLeave(player)
end)
for _, player in Players:GetPlayers() do
clickCount[player] = 0
end
If you can help me with this issue I will be very greatful.




