Player name is not showing in textlabel

  1. What do you want to achieve? Keep it simple and clear!

Hi, I want to get the player name from a localscript into a textlabel

  1. What is the issue? Include screenshots / videos if possible!

there is no error in the output and the player name doesn’t show in the text

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I have tried doing some research on Google and Developer forum but I couldn’t find a solutions to it.

local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local ShopBlur = game.Lighting:WaitForChild("ShopBlur")
local ShopFrame = script.Parent:WaitForChild("ShopFrame")
local SEB = script.Parent.ShopFrame:WaitForChild("ShopExitButton")
local ShopButton = script.Parent.DisplayShop.DisplayButtons:WaitForChild("ShopButton")
local PlayerNameDisplay = script.Parent.ShopFrame:WaitForChild("PlayerNameDisplay")
local canToggle = true


ShopButton.MouseButton1Click:Connect(function()
	if ShopFrame.Visible == false and canToggle then
		canToggle = false
		ShopFrame.Visible = true
		ShopBlur.Enabled = true
		PlayerNameDisplay.Text = "Welcome to the Shop " .. player.Name
		ShopFrame:TweenPosition(
			UDim2.new(0.131, 0,0.091, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Quart,
			.9,
			false
		)
		player.Character:WaitForChild("Humanoid").WalkSpeed = 0
		player.Character:WaitForChild("Humanoid").JumpPower = 0

		delay(1, function()
			canToggle = true
		end)

	elseif canToggle then
		canToggle = false
		
		SEB.MouseButton1Click:Connect(function()
			ShopFrame:TweenPosition(
				UDim2.new(0.131, 0,-0.895, 0),
				Enum.EasingDirection.In,
				Enum.EasingStyle.Quart,
				.9,
				false
			)

		delay(1, function()
			player.Character:WaitForChild("Humanoid").WalkSpeed = 16
			player.Character:WaitForChild("Humanoid").JumpPower = 50
			ShopBlur.Enabled = false
			ShopFrame.Visible = false
			canToggle = true
			end)
		end)
	end
end)

I hope someone could help me with this. Thanks!

1 Like

Does PlayerNameDisplay visible?

I have not touched playerNameDisplay tho nor do I know what it is

Is it something to do with the player Display name?

It must be visible by default. If you didn’t touch it, that not problem. I have an idea why it didn’t work. Add some wait() before of change text. (Edited: I don’t think .CharacterAdded:Wait() actually help.)

it is not working. This is the full script btw

local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local ShopBlur = game.Lighting:WaitForChild("ShopBlur")
local ShopFrame = script.Parent:WaitForChild("ShopFrame")
local SEB = script.Parent.ShopFrame:WaitForChild("ShopExitButton")
local ShopButton = script.Parent.DisplayShop.DisplayButtons:WaitForChild("ShopButton")
local PlayerNameDisplay = script.Parent.ShopFrame:WaitForChild("PlayerNameDisplay")
local canToggle = true


ShopButton.MouseButton1Click:Connect(function()
	if ShopFrame.Visible == false and canToggle then
		canToggle = false
		ShopFrame.Visible = true
		ShopBlur.Enabled = true
		PlayerNameDisplay.Text = "Welcome to the Shop " .. player.Name
		ShopFrame:TweenPosition(
			UDim2.new(0.131, 0,0.091, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Quart,
			.9,
			false
		)
		player.Character:WaitForChild("Humanoid").WalkSpeed = 0
		player.Character:WaitForChild("Humanoid").JumpPower = 0

		delay(1, function()
			canToggle = true
		end)

	elseif canToggle then
		canToggle = false
		
		SEB.MouseButton1Click:Connect(function()
			ShopFrame:TweenPosition(
				UDim2.new(0.131, 0,-0.895, 0),
				Enum.EasingDirection.In,
				Enum.EasingStyle.Quart,
				.9,
				false
			)

		delay(1, function()
			player.Character:WaitForChild("Humanoid").WalkSpeed = 16
			player.Character:WaitForChild("Humanoid").JumpPower = 50
			ShopBlur.Enabled = false
			ShopFrame.Visible = false
			canToggle = true
			end)
		end)
	end
end)

Is ShopFrame visible? or add print() to check if statement work.

ShopFrame is not visible. I added print(“Works”) in the if statement and it prints
image

that why text doesn’t work. Try to make ShopFrame Visible and see if it works. Also where did you put your print().

the ShopFrame is not visible by default but when the player click on the ShopButton it will make the ShopFrame visible

EDIT: this is where the print is
image

Hmm. I have no clue why it doesn’t work then. Wait for others to reply or try to look up more or if possible, try to remake it (sometimes it work). :wave:t3:

Try placing a local script into StarterCharacterScripts then do something like this

local player = game:GetService(“Players”).LocalPlayer
game:GetService(‘Players’).LocalPlayer:WaitForChild(‘PlayerGui’).YOURPATHTOTHETEXT = "Welcome to the Shop " .. player.Name

Same thing. It doesn’t show the player name for some reason

local player = game:GetService("Players").LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local ShopBlur = game.Lighting:WaitForChild("ShopBlur")
local ShopFrame = script.Parent:WaitForChild("ShopFrame")
local SEB = script.Parent.ShopFrame:WaitForChild("ShopExitButton")
local ShopButton = script.Parent.DisplayShop.DisplayButtons:WaitForChild("ShopButton")
local PlayerNameDisplay = script.Parent.ShopFrame:WaitForChild("PlayerNameDisplay")
local canToggle = true

game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui").SettingsUI.ShopFrame.PlayerNameDisplay.Text = "Welcome to the Shop " .. player.Name 


ShopButton.MouseButton1Click:Connect(function()
	if ShopFrame.Visible == false and canToggle then
		canToggle = false
		ShopFrame.Visible = true
		ShopBlur.Enabled = true
		ShopFrame:TweenPosition(
			UDim2.new(0.131, 0,0.091, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Quart,
			.9,
			false
		)
		player.Character:WaitForChild("Humanoid").WalkSpeed = 0
		player.Character:WaitForChild("Humanoid").JumpPower = 0

		delay(1, function()
			canToggle = true
		end)

	elseif canToggle then
		canToggle = false
		
		SEB.MouseButton1Click:Connect(function()
			ShopFrame:TweenPosition(
				UDim2.new(0.131, 0,-0.895, 0),
				Enum.EasingDirection.In,
				Enum.EasingStyle.Quart,
				.9,
				false
			)

		delay(1, function()
			player.Character:WaitForChild("Humanoid").WalkSpeed = 16
			player.Character:WaitForChild("Humanoid").JumpPower = 50
			ShopBlur.Enabled = false
			ShopFrame.Visible = false
			canToggle = true
			end)
		end)
	end
end)

image

are there any other errors in your output?

Nope, no errors at all. Except for this one
image

Change the start of your script to this, and be sure its a local script in startercharacterscripts

local player = game:GetService(“Players”).LocalPlayer
local PG = game:GetService(‘Players’).LocalPlayer:WaitForChild(‘PlayerGui’)
local Character = player.Character or player.CharacterAdded:Wait()
local ShopBlur = game.Lighting:WaitForChild(“ShopBlur”)
local ShopFrame = PG.PATHTOSHOPFRAME:WaitForChild(“ShopFrame”)
local SEB = ShopFrame:WaitForChild(“ShopExitButton”)
local ShopButton = PG.PATHTODISPLAYBUTTONS:WaitForChild(“ShopButton”)
local PlayerNameDisplay = ShopFrame:WaitForChild(“PlayerNameDisplay”)
local canToggle = true
PG.SettingsUI.ShopFrame.PlayerNameDisplay.Text = "Welcome to the Shop " .. player.Name

Let me know if i left in any mistakes or if it’s not working

Hey, sorry for the late reply… it still doesn’t work though. There isn’t any error in the output.

local player = game:GetService("Players").LocalPlayer
local PG = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui")
local Character = player.Character or player.CharacterAdded:Wait()
local ShopBlur = game.Lighting:WaitForChild("ShopBlur")
local ShopFrame = PG.SettingsUI:WaitForChild("ShopFrame")
local SEB = ShopFrame:WaitForChild("ShopExitButton")
local ShopButton = PG.SettingsUI.DisplayShop.DisplayButtons:WaitForChild("ShopButton")
local PlayerNameDisplay = ShopFrame:WaitForChild("PlayerNameDisplay")
local canToggle = true
PG.SettingsUI.ShopFrame.PlayerNameDisplay.Text = "Welcome to the Shop " .. player.Name

ShopButton.MouseButton1Click:Connect(function()
	if ShopFrame.Visible == false and canToggle then
		canToggle = false
		ShopFrame.Visible = true
		ShopBlur.Enabled = true
		ShopFrame:TweenPosition(
			UDim2.new(0.131, 0,0.091, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Quart,
			.9,
			false
		)
		player.Character:WaitForChild("Humanoid").WalkSpeed = 0
		player.Character:WaitForChild("Humanoid").JumpPower = 0

		delay(1, function()
			canToggle = true
		end)

	elseif canToggle then
		canToggle = false

		SEB.MouseButton1Click:Connect(function()
			ShopFrame:TweenPosition(
				UDim2.new(0.131, 0,-0.895, 0),
				Enum.EasingDirection.In,
				Enum.EasingStyle.Quart,
				.9,
				false
			)

			delay(1, function()
				player.Character:WaitForChild("Humanoid").WalkSpeed = 16
				player.Character:WaitForChild("Humanoid").JumpPower = 50
				ShopBlur.Enabled = false
				ShopFrame.Visible = false
				canToggle = true
			end)
		end)
	end
end)

image

Hey so I think this might fix your issue, but what I would do is have like a client local script and have there all the gui handling not creating a script for shop, one for something else. But as advice I would just manage and clean my code since your code is messy and not really that readable. Here is your code a bit more cleaned up and I hope this helped you!


-- also sorry if I messed up some variables or some code --

local canToggle = true

local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")

local ShopBlur = game.Lighting:WaitForChild("ShopBlur")

local Player = Players.LocalPlayer
local PlayerGui = Players.LocalPlayer:WaitForChild("PlayerGui")
local Character = Player.Character or Player.CharacterAdded:Wait()

local ShopFrame = PlayerGui.SettingsUI:WaitForChild("ShopFrame")
    local ShopExitButton = ShopFrame:WaitForChild("ShopExitButton")
    local ShopButton = PlayerGui.SettingsUI.DisplayShop.DisplayButtons:WaitForChild("ShopButton")
    local PlayerNameDisplay = ShopFrame:WaitForChild("PlayerNameDisplay")

-- [[ INIT ]] --
PlayerGui.SettingsUI.ShopFrame.PlayerNameDisplay.Text = "Welcome to the Shop " .. player.Name

-- [[ UTILITIES ]] --
function SetJumpWalkAttributes(Arg1, Arg2, Arg3)

    local Humanoid = Arg1

    Humanoid.WalkSpeed = Arg2
    Humanoid.JumpPower = Arg3
    --return true
end

-- [[ CONNECTIONS ]] --
ShopButton.MouseButton1Click:Connect(function()
	if ShopFrame.Visible == false and canToggle then
		canToggle = false
		ShopFrame.Visible = true
		ShopBlur.Enabled = true
		ShopFrame:TweenPosition(
			UDim2.new(0.131, 0,0.091, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Quart,
			.9,
			false
		)

        SetJumpWalkAttributes(Player.Character:WaitForChild("Humanoid"), 0, 0)

		delay(1, function()
            
			canToggle = true
		end)

	elseif canToggle then

		canToggle = false

		ShopExitButton.MouseButton1Click:Connect(function()
			ShopFrame:TweenPosition(
				UDim2.new(0.131, 0,-0.895, 0),
				Enum.EasingDirection.In,
				Enum.EasingStyle.Quart,
				.9,
				false
			)

			delay(1, function()

                SetJumpWalkAttributes(Player.Character:WaitForChild("Humanoid"), 16, 50)

				ShopBlur.Enabled = false
				ShopFrame.Visible = false
				canToggle = true
			end)
		end)
	end
end)