Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help with player joining script?

Asked by
Bman8765 270 Moderation Voter
10 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

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)
0
*Why* do you want to do this? This is almost certainly a really bad design choice. BlueTaslem 18071 — 10y
0
I need it for the card game I'm working on. Bman8765 270 — 10y

1 answer

Log in to vote
0
Answered by
SirNoobly 165
10 years ago

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)
Ad

Answer this question