I want to implement an automatic translation feature for chat messages in my Roblox game. When a player clicks a button, a message from a list of sayings should be translated into the player’s preferred language and then displayed in the chat.
The current implementation of the translation feature isn’t working as expected. I’m struggling to correctly translated messages.
local OriginalSayings = {"What's your favorite childhood memory?", "If you could visit any place in the world, where would you go first?",
"What's your favorite movie of all time?",
"If you could have any superpower, what would it be?",
}
local Sayings = OriginalSayings
local ts = game:GetService("TweenService")
local cs = game:GetService('Chat')
local cooldown = 3
local buttonsFolder = game.Workspace.AssetsFolder.Buttons
local buttons = {}
for i, v in buttonsFolder:GetDescendants() do
if v:IsA("ClickDetector") then
table.insert(buttons, v)
end
end
for i, v in buttons do
v.MouseClick:Connect(function()
if v.Parent:FindFirstChild("Cooldown") then return end
local cooldownI = Instance.new("BoolValue", v.Parent)
cooldownI.Name = "Cooldown"
local sound = Instance.new("Sound", v.Parent)
sound.SoundId = "rbxassetid://18186754642"
sound:Play()
local tween = ts:Create(v.Parent, TweenInfo.new(.3), {CFrame = v.Parent.Parent.PressedPoint.CFrame})
tween:Play()
spawn(function()
tween.Completed:Wait()
local t2 = ts:Create(v.Parent, TweenInfo.new(.3), {CFrame = v.Parent.Parent.OriginalPos.CFrame})
t2:Play()
return
end)
local Num = math.random(1,#Sayings)
cs:Chat(v.Parent, Sayings[Num])
table.remove(Sayings, Num)
if #Sayings<1 then
Sayings = OriginalSayings
end
task.wait(cooldown)
sound:Destroy()
cooldownI:Destroy()
end)
end