Need Help Finding Localplayer For A Keep Out Poster

image

I Need To Find The Name Of The Localplayer, And Hopefully Not Need To Ask About Localplayer Again

Doesnt Matter How. But I Just Need Something. This Is A One Player Game

1 Like

game.Players.LocalPlayer or the player near the poster?

Local Player. This Wont Work

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local Text = script.Parent.SurfaceGui.Room.Text

Text = player.."'s Room"

Just some nitpicking first to help, then I’ll get to the actual problem:

  1. If the poster changes from a local script, then it won’t show to the server. Try to find out to get it into a server script.
  2. If this is in a server script, then don’t use LocalPlayer. It won’t work on the server. Again, try to figure out another way to get the player.

All right, now the actual problem!
You’re probably getting an error for concatenating an instance (the player) with a string. Do player.Name or player.DisplayName instead of just player. Next, you’re just reassigning a variable, not changing the text. So change the Text variable to:

local room = script.Parent.SurfaceGui.Room

room.Text = player.Name.."'s Room"

That’s it. Please, open the console next time, and try to tell us the errors that appear there.

Since this is a single player game and you are using a script to retrieve the player, you can do this.

local Player = game:GetService("Players"):GetPlayers()[1]
1 Like

script.Parent.SurfaceGui.Room.Text = game.Players:GetPlayers()[1].DisplayName

Make sure that is a NORMAL script inside of the part that has the SurfaceGui.

1 Like
local players = game:GetService("Players")
local player = players.LocalPlayer
local playerId = player.userId
local username = players:GetNameFromUserIdAsync(playerId)

This will work in any local script providing you’ve placed the script in a valid location.

1 Like

That’s a little complex just to get the player. OP said that it was a single-player game, so they could just do game.Players:GetPlayers()[0] in a server script or local script.

It gets all the info about a user right from the get-go (the player object, the player’s user ID & the player’s name), so if any of it is required later then it can be simply accessed.

1 Like

You don’t know if he needs it though, and the extra code is not necessary.