Clone button on player added event

Hello there, i want to make something where whenever a player joins it clones a button and when they leave it destroys it.

The thing is it clones my name but it doesnt, when i went into a test server with 2 players it only cloned player 1 not player 2 but i need it to clone everybody who joins.

1 Like

Is your code setup like this?

local Buttons = {};
game:GetService("Players").PlayerAdded:Connect(function(Plr)
    local Button = Button:Clone();
    Button.Parent = Plr:WaitForChild("PlayerGui");
    Buttons[Plr] = Button;
end);
--//
game:GetService("Players").PlayerRemoving:Connect(function(Plr)
     if(Buttons[Plr])then
        Buttons[Plr]:Destroy();Buttons[Plr] = nil;
    end;
end);

Why are you even doing this may I ask

For a ban system, u see rolve’s ban system. On the left side it has all the players names and when a player leaves it destroys the text button.

and no my code is set up like this:

game.Players.PlayerAdded:Connect(function(Player)
local Yes = Yes:Clone()
Yes.Parent = game.Players.LocalPlayer.PlayerGUI.ScreenGUI
Yes.Text = Player.Name
end)

game.Players.PlayerAdded:Connect(function(Player)
Player.PlayerGui.ScreenGUI.TextButton:Destroy()
end)

I don’t quite understand what you mean by rolve’s ban system, I don’t think they’ll have that open for the public either? Can you possibly provide a screenshot?

Okay… (30 charsssssssssssssssssssss)

Capture

Ahh, I’ve never seen that lol. But personally I would make this as a normal client feature, create all the client sided scripts for it, events etc. Then place it into ServerStorage, Whenever a player joins, you can then clone the entire UI into there PlayerGui (Assuming this is only for admins)

local Whitelist = {1,4013,31};

game:GetService("Players").PlayerAdded:Connect(function(Plr)
    local Whitelisted = table.find(Whitelist, Plr.UserId);
        if Whitelisted then
            --<Clone the gui and give it to them
        end;
end)

no its like i want to clone a textbutton and the textbutton’s text will be the players name everytime somebody joins.

You can just set that up locally within the panel, pretty sure you can listen for player added events on the client, There’s really no need for the array though.

1 Like

So everytime a player joins it will clone and when they leave it will destroy?

1 Like