Okay so I'm making a code that basically changes the name of a script when a player joins. The script name is Player1 but when the player joins I want the script to be the players name instead. Here is the code I have (Below) but it in no way shape or form works...I should note I have 2 scripts like this which is why I need values so that if player1 has already been named a.k.a player1 has joined then it will rename player2 script instead of player1. Thanks, if you have any questions just ask. Any wiki links, or source code would be awesome!
---------------------------------------------------------------------------------------------------- --Insert VARIABLES Below ---------------------------------------------------------------------------------------------------- Player1named = game.Workspace.Player1.Named.Value Playersonline = game.Workspace.PlayerCount.PlayersOnline.Value local Players = game:GetService("Players") ---------------------------------------------------------------------------------------------------- print("Player 1 script working") repeat wait() function onPlayerAdded(player) if Player1named == false then print("Player 1 not online, changing this") game.Workspace.Player1.Name = player.Name Player1named = true elseif Player1named == true then print("Player 1 already online") return end end until Playersonline == 2 Players.PlayerAdded:connect(onPlayerAdded)
You would just get the script as a variable beforehand then change its name when a player joins.
local nameScript = workspace.Player1 -- You need to do this as the name changes. game:GetService("Players").PlayerAdded:connect(function(player) -- Runs every time a player joins nameScript.Name = player.Name end)