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.

--ignore the stuff that's commented out below kthxbye

local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
--local baseClaim = game:GetService("ReplicatedStorage").baseClaim

function onPlayerAdded()
    local playerName = localPlayer.Name

    print(playerName)

    --baseClaim:FireServer()
end

Players.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:

String=Instance.New("String Value")
String.Value = game.Players.LocalPlayer.Name

print(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