Accessing PlayerGui

Changing PlayerGui Text Label
Hello! I want acess PlayerGui, And inside Player Gui have a ScreenGui and a TextLabel
But its giving me a Error!
image
This is my script :

local cd = script.Parent.ClickDetector
local Player = game.Players.LocalPlayer
local PlayerGui = Player.PlayerGui
local gui = PlayerGui.TimerGui
local timerLabel = gui.TimerLabel
local timer = 30
--code--
cd.MouseClick:Connect(function(tocado)
	if tocado.ReadyForHat.Value == '1' then
		timerLabel.Text = timer
		timerLabel.Visible = true
		wait(1)
		repeat
			timer -= 1
			timerLabel.Text = "You need wait" ..timer.. "For try a new hat!"
		until
		timer <= 0
		timerLabel.Visible = false		
	end
end)

Judging by that green line, are you trying to get th LocalPlayer in a server script? It doesn’t work like that, you have to get the label in the Event and use the player that MouseClick Gives, aka, your tocado paramter

local cd = script.Parent.ClickDetector
local timer = 30
--code--
cd.MouseClick:Connect(function(tocado)
	if tocado.ReadyForHat.Value == '1' then
		local gui = tocado.PlayerGui.TimerGui
		local TimerLabel = gui.TimerLabel
		timerLabel.Text = timer
		timerLabel.Visible = true
		wait(1)
		repeat
			timer -= 1
			timerLabel.Text = "You need wait" ..timer.. "For try a new hat!"
		until timer <= 0
		timerLabel.Visible = false		
		timer = 30
	end
end)

I also made it reset the timer variable since it didn’t do that

Edit: Besides that error, you’re gonna have to fix up your script since the player can still click and cause the timer to go down faster instead of how you were intending

2 Likes

I got it, ill try this rn, thank you for helping

1 Like

Once again, anytime! If you have even more issues don’t be afraid to make another post!