Can anyone tell me what's wrong?

Well, I’m not sure if this is the right topic to ask for help as I’m new to this site, but I have a problem with the script below. Every time a player joins the game, the text stays written as ‘Locked,’ even though the player has the amount of ‘Wins’ or even more. The text only shows the correct name after the player resets. Could someone please explain how to solve this issue? And look, I’ve tried several ways to solve it, but I couldn’t.

local uiu = script.Parent["UIU"]
local plr = game.Players.LocalPlayer

-- Localize o jogador
local player = game.Players.LocalPlayer

if player.leaderstats.Win.Value >15 then
	uiu.Text = ""..uiu.Name
else
	uiu.Text = "Locked"
end

3 Likes

Im pretty sure its because that script is running before your player’s data is fully loaded, You can just wait until the “player.leaderstats.Win.Value” Has changed, Example:

local uiu = script.Parent["UIU"]
local plr = game.Players.LocalPlayer

-- Localize o jogador
local player = game.Players.LocalPlayer

player:WaitForChild("leaderstats"):FindFirstChild("Win").Changed:Connect(function()
if player.leaderstats.Win.Value >15 then
	uiu.Text = ""..uiu.Name
else
	uiu.Text = "Locked"
end
end)


Note that this is example code, and shouldnt be copied and pasted, im simply giving what i think could work.

2 Likes

You only indexed it once, Kenny’s solution is the correct way to do it.

1 Like

Thank you so much! You really helped me out with my problem. I don’t know much about programming, but I appreciate it a lot. I’m trying to learn, and I already know some things, but this was new to me.

1 Like

wow are you the realllllllllll Kenny

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.