What you would want to do is create a function which is called whenever a player joins. This function would check if the player is the creator of the place. If the player is the creator of the place, it would add a team to the game which only the creator could join. I added some extra functionality to the script, assuming you would want the team to remove itself when you leave, and I added the option for others to join the team when you're gone if it's not deleted (which is disabled by default). I also made it an option to prevent you from joining other teams.
Feel free to look through the code and see how it works.
01 | local preventJoiningOtherTeams = true ; |
02 | local removeTeamUponExit = true ; |
03 | local letOthersJoinTeamUponExit = false ; |
04 | local OwnerTeam = Instance.new( "Team" ) |
05 | OwnerTeam.Name = "Team Name" |
06 | OwnerTeam.TeamColor = BrickColor.new( "Really red" ) |
08 | function onPlayerAdded(player) |
09 | if player.userId = = Game.CreatorId then |
10 | OwnerTeam.AutoAssignable = false |
11 | OwnerTeam.Parent = Game:GetService( "Teams" ) |
12 | player.TeamColor = OwnerTeam.TeamColor |
13 | player.Changed:connect( function (property) |
14 | if preventJoiningOtherTeams and property = = "TeamColor" and player.TeamColor ~ = OwnerTeam.TeamColor then |
15 | player.TeamColor = OwnerTeam.TeamColor; |
21 | function onPlayerRemoving(player) |
22 | if player.userId = = Game.CreatorId then |
23 | if removeTeamUponExit then |
24 | OwnerTeam.Parent = nil |
25 | elseif letOthersJoinTeamUponExit then |
26 | OwnerTeam.AutoAssignable = true |
31 | Game:GetService( "Players" ).PlayerAdded:connect(onPlayerAdded) |
32 | Game:GetService( "Players" ).PlayerRemoving:connect(onPlayerRemoving) |
Locked by FearMeIAmLag
This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?