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

Trying to print the LocalPlayer's name doesn't do anything? (it's in a local script btw)

Asked by
o_Blyzo 12
6 years ago

Hi, I'm trying to get the LocalPlayer's name for various things, and as a test I wanted to just print the value of their name. However, with the code I've got, nothing is happening when I run the game.

01--ignore the stuff that's commented out below kthxbye
02 
03local Players = game:GetService("Players")
04local localPlayer = Players.LocalPlayer
05--local baseClaim = game:GetService("ReplicatedStorage").baseClaim
06 
07function onPlayerAdded()
08    local playerName = localPlayer.Name
09 
10    print(playerName)
11 
12    --baseClaim:FireServer()
13end
14 
15Players.PlayerAdded:Connect(onPlayerAdded)

That's the code, it's within a LocalScript that is placed in a normal ScreenGui within StarterGui.

I'm getting no errors or anything from this script, it's just not printing anything.

Thanks for any help.

1 answer

Log in to vote
0
Answered by 6 years ago

Client script:

1String=Instance.New("String Value")
2String.Value = game.Players.LocalPlayer.Name
3 
4print(String.Value)

If anything goes wrong let mde know and I'll see to it...

0
It works by itself in a LocalScript but if I add it to the Script I posted above, it still doesn't work? o_Blyzo 12 — 6y
0
For reference, I added the first two lines of your script (the ones that define the String) to before the onPlayerAdded() function in mine. I added the print(string.value) to mine where it says print(PlayerName), i replaced it o_Blyzo 12 — 6y
0
It could be that you're not loaded yet, and the game executes your code before-hand. As there is no way for it to prioritise events except for yourself. E.g. Using a yield command, using RepFirst etc... StateSector 8 — 6y
Ad

Answer this question