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)
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.
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.
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
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