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

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

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

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

3 comments

0

It works by itself in a LocalScript but if I add it to the Script I posted above, it still doesn't work?

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

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

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