Why my simple localscript wont work?

So, im trying to make a localscript that detects the user language but it doesnt work, when the player joins the game they have a menu to choose their language (options are spanish and english) when they click the flag of the language a remote event fires with the language chosen by the player, then all the text in the game updates to the language. the text updater doesnt work tho.

Solutions ive tried: Using GetPropertyChangedSignal.

Script:

repeat wait() until game.Loaded

local player = game.Players.LocalPlayer
local mensaje = script.Parent

repeat wait() until player.leaderstats["🗣️"].Value == "???"

player.leaderstats["🗣️"].Changed:Connect(function(language)
	if language == "???" then
		return
	elseif language == "🇪🇸" then
		script.Parent.Text = "Selecciona el boton correcto."
	elseif language == "🇺🇸" then
		script.Parent.Text = "Pick the correct button."
	end
end)

So what is ‘:speaking_head:’, is that the name of a string value in the leaderstats? why would you name something with a symbol.

to make it look good idk, but that doesnt matter, bc if that was the issue the remote event wouldnt work.

Might not be a good idea to use non-ASCII characters for strings since you never know whether or not they’re properly supported.
Does the .Changed event fire at all? Try putting a print function at the top of the function and see if it does anything

nope it doesnt, same with GetPropertyChangedSignal

Check the StringValue in the explorer window and see if it actually changes

Ok, here is some ‘improved’ code. However I highly beloeve a fault in the code is the weird text/symbols used throughout. I highly recommend you change this

Just to note, on the first line of the original code, localscripts do not run until the game is fully loaded by default unless they are an ancestor of ReplicatedFirst. Even if they were and you intended for the code to yield until it is loaded it is hugely inefficent to do repeat wait() until game.Loaded instead of game.Loaded:Wait(). I have removed it though so re-add it if you wish.

local player = game.Players.LocalPlayer
local mensaje = script.Parent

player.leaderstats["🗣️"].Changed:Connect(function(language)
	if language == "🇪🇸" then
		script.Parent.Text = "Selecciona el boton correcto."
	elseif language == "🇺🇸" then
		script.Parent.Text = "Pick the correct button."
	end
end)

it changes the value in the leaderstats to the USA flag emoji
image

didnt work , any other possible solution?

I would suggest you change out the special characters to just regular words. When you’re troubleshooting you want to keep things simple.

In case the problem lies on the connection, you can try using an infinite loop to brute-force the debugger

local value = player.leaderstats["🗣️"]
while task.wait() do
  local v = value.Value
  print(v, v == '🇪🇸', v == '🇺🇸')
end

Use this to see exactly what is happening to the value

  1. You should not need to fire any remote events to change the language of objects in the game locally. Unless you are trying to edit text in inaccessible areas such as ServerStorage. I’m not sure if you already understand this but it was worth mentioning.

Instead, once the player chooses their language in a local script. Just convert all of the games text from that same local script, you don’t need to look for any changed properties.

Example:

--Selected language buttons for the example...
local USA_Button = Instance.new("TextButton")--Or whatever your button is.
local Brazil_Button = Instance.new("TextButton")--Or whatever your button is

local Player = game:GetService("Players").LocalPlayer
local PlayerGui = Player.PlayerGui
local Debounce = false

local function ConvertText(Language)
	if Language == "English" then--Convert other texts to english.
		PlayerGui.Your_UI.Text = "Pick the correct button."
	elseif Language == "Portugese" then--Convert other texts to portugese.
		PlayerGui.Your_UI.Text = "Selecciona el boton correcto."
	end
end
USA_Button.MouseButton1Click:Connect(function()
	if Debounce == false then
		Debounce = true
		ConvertText("English")--Convert other texts to english.
		wait(1)
		Debounce = false
	end
end)
--Brazil button is pressed.
Brazil_Button.MouseButton1Click:Connect(function()
	if Debounce == false then
		Debounce = true
		ConvertText("Portugese")--Convert other texts to portugese.
		wait(1)
		Debounce = false
	end
end)
--This is just an example of what I mean!
1 Like

still didnt work, i changed it to “-”

That’s for debugging, you’re supposed to put that in your localscript and check the output window

1 Like

works very well, thank you!
image

Bruh i…
I’ll take it, you’re welcome and good luck.

1 Like

i just…thinked about it and i did it wrong lol

1 Like