Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help with player joining script?

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)

2 comments

0

Why do you want to do this? This is almost certainly a really bad design choice.

0

I need it for the card game I'm working on.

1 answer

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.