Why is the text not changing?

Greetings,

I am making a language system and I have a numbervalue and every number represents a language. The value saves fine and everything is loading fine, but despite that, the text is not changing when the player enters the game and no error show up. Code is shown down below:

wait(2)
local player = game.Players.LocalPlayer
local char = player.leaderstats or player.leaderstatsAdded:Wait()
local char2 = char.Language or char.LanguageAdded:Wait()
local language = char2

game.Players.PlayerAdded:Connect(function(player)
	wait(2)
	if language.Value == 1 then
		script.Parent.Text = "English (UK)"
	elseif language.Value == 2 then
		script.Parent.Text = "Română (RO)"
	end
end)

Please help, thanks!

1 Like

at the start of the script, you have a wait(2) and char and char2 may cause an even longer wait, the player might be joining before the PlayerAdded event is even connected. Add a print(‘player joined’) inside of the PlayerAdded event to check if it is being fired.

edit: also this is a script right?

I think the reason why this script doesn’t work is because it’s a local script. “PlayerAdded” doesn’t work in local scripts.

local player = game.Players.LocalPlayer
local char = player.leaderstats or player.leaderstatsAdded:Wait()
local char2 = char.Language or char.LanguageAdded:Wait()
local language = char2
if language.Value == 1 then
	script.Parent.Text = "English (UK)"
elseif language.Value == 2 then
	script.Parent.Text = "Română (RO)"
end

Since this script is a local script, it will run when the player enters the game.

1 Like

Hey, I have placed print as you said and I can’t see it in the output, so I guess it doesn’t get triggered. This is a local script as you can see it says

local player = game.Players.LocalPlayer

I have written wait(2) because it would say that leaderstats is not a member of Folder ‘Players.Doom_Vickstar999’

if you have a PlayerAdded inside a local script, it ill not fire for the the player that owns the local script, and only when another player joins the game, so maybe try what @fatih1106 suggested

edit: also, try using :WaitForChild()
eg

player:WaitForChild('leaderstats')
1 Like

It worked, thanks a bunch. I didn’t realize that since I have seen the PlayerAdded property when writing the code.

I have used before but, it always said: infinite yield possible on leaderstats or something like that, and someone recommended me to use what I am currently using. And it works flawlessly.

leaderstatsAdded and LanguageAdded aren’t even existing event signals.

local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
local language = leaderstats:WaitForChild("Language")

if language.Value == 1 then
	script.Parent.Text = "English (UK)"
elseif language.Value == 2 then
	script.Parent.Text = "Română (RO)"
end

This is all that is needed.