What do you want to achieve?
A text label that displays the local player’s username (I basically want to put a text on a gravestone that displays the players username)
What is the issue?
I tried scripting it myself but I’m quite unexperienced so I couldn’t manage to, also the yt tutorials I watched were useless.
What solutions have you tried so far?
There are some similar topics I found but none of them helped me really.
This is what I tried and also found on tutorials… I even dont know if Im atleast on the right path
local player = game.players.localplayer
text = script.parent
text.text = player.name
Thanks for your help! Looking forward to your replies
It seems like you’re on the right path, but there are some minor corrections to make in your code. LIke how getting the name of the Player would be with a capital P instead of a lowercase.
Here’s an example:
local player = game.Players.LocalPlayer
local textLabel = script.Parent -- Assuming the TextLabel is a child of the script
-- Set the Text property of the TextLabel to the player's username
textLabel.Text = player.Name
You are doing things right but there are some mistakes like:
game.players.localplayer should be game.Players.LocalPlayer with the correct capitalization and If you’re dealing with a TextLabel, then the Text property (with a capital T) should be used to change its displayed text.
game.players.localplayer should be game.Players.LocalPlayer with the correct capitalization.
If you’re dealing with a TextLabel, then the Text property (with a capital T) should be used to change its displayed text.
-- Assuming this is a LocalScript
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local textLabel = script.Parent
textLabel.Text = localPlayer.Name
Good stuff, but also here: Use a normal script, with RunContext set to client. That’s a property under the script.
The use-case here is for a gravestone, which is highly likely to be a descendant of the workspace. Normal local scripts don’t run there, but RunContext = Client ‘regular’ scripts do.