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

How To Detect A Users Name On Joining To Be Used In a Script?

Asked by
RoboFrog 400 Moderation Voter
10 years ago

As of now, I have created the following script:

local gpath = game.StarterGui.ScreenGui.BackFrame.MidFrame
local ipath = game.Workspace.Tycoon.Tycoon.InvInt
local update1 = game.Workspace.Tycoon.Tycoon.InvInt.Stone
local update2 = game.Workspace.Tycoon.Tycoon.InvInt.StoneB
local character = game.workspace.Tycoon.Tycoon.OwnerString.Value -- Temporary placeholder
local LGui = game.Players.character.PlayerGui.ScreenGui.BackFrame.MidFrame --  Works when character is labeled as ROBOFROG

function TUpdate()
print('fire')
LGui.StoneFrame.Ore.Text = (tostring(ipath.Stone.Value))
gpath.StoneFrame.Bar.Text = (tostring(ipath.StoneB.Value))

end

update1.Changed:connect(TUpdate)
update2.Changed:connect(TUpdate)

Basically, this is a script (that does currently work) which works like a local script with local references, however is not a local script. As of now though, it doesn't differentiate between people. It is only working currently if I manually load my name into the script where it says "character" inside the LGui variable.

How would I be able to make this script automatically insert the name of the user into the "character" local variable? I'm guessing it'll have something to do with children, but I haven't been able to get that to work yet.

The total purpose of the script shouldn't matter, but in case it is truly needed, I can type it all out. But, as of now, I think all that needs to be changed is accessible in this one script.

Any help is much appreciated, and thank you for reading!

2 answers

Log in to vote
1
Answered by 10 years ago

Explained in comments.

function playerAdded(player)
    repeat wait() until player.Character
    local character = player.Name --Simply makes the Character variable the player's name. From there, you can change Gui text, Humanoid names, or anything you need with the Character variable.
end
game.Players.PlayerAdded:connect(playerAdded)
0
Whenever I use that variable, it tells me "character is not a valid member of Players". It's definitely a good approach, however! RoboFrog 400 — 10y
0
I added a line of code, try now. SlickPwner 534 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

Hmm, since I do not know what this script does

I know you can do this, but this is all I know of, sorry if this was no help :(

game.Players.LocalPlayer
0
No problem, I appreciate the reply! Sadly, that won't work for me, since it isn't (and can't be) a local script. If you happen to know of any alternatives to LocalPlayer which function in regular scripts, I'd love to know. RoboFrog 400 — 10y

Answer this question