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