Player Button / Please help

  1. **What do you want to achieve?
    hello guys I would like to make sure that each player of a different team / color has his own button!
    that only he can use and see .

  2. **What is the issue?
    i don’t know how i should do if i have to give a value to the player and then use that value in the script to make the player button visible…

3 Likes

if you assign player team on spawn then this idea should work

local TeamButtonFolder = --(your path to a folder that contains all of the team buttons)--
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
Players.PlayerAdded:Connect(function(plr)
	assignPlayerTeam() -- this block of code should assign player's team
	local teambutton = TeamButtonFolder:WaitForChild(plr.Team.Name):Clone() -- make sure the names of buttons are te same as team names
	teambutton.Parent=plr.PlayerGui:WaitForChild("ScreenGui") -- make sure you put "ScreenGui" in startergui.
end)

If you can change teams in your game, you can easily detect that using plr:GetPropertyChangedSignal(“Teams”) and then you can remove the old team button and assign a new one.

2 Likes


I did well ? because I don’t like it

2 Likes

I removed the fifth line that I don’t need! could that be the problem?

2 Likes

Put the buttons that you edited to your liking in a folder that is in serverstorage. The 5th line that you deleted is basically a replacement for a block of code that assigns the player to a certain team if you haven’t written that already. If the player is not assigned his team when joined, then a different approach should be considered.

2 Likes

for the row i deleted i have this script

local function FindEmptyTeam(): Team | nil
for _, team in ipairs(game.Teams:GetTeams()) do
if #team:GetPlayers() < 1 then
return team
end
end
return nil
end

game.Players.PlayerAdded:Connect(function(Player)
local getAssignedTeam = FindEmptyTeam()
if getAssignedTeam and typeof(getAssignedTeam) == “Instance” then
Player.Team = getAssignedTeam
end
end)

what do you think ?
anyway thanks, everything works now

Everything looks good, good work

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.