Hello I am quite new to coding and recently wanted to make an overhead gui that showed a players country and username I used the GetCountryRegionForPlayerAsync
to get the basic code and then added it on to an overhead I had already made
local LocalizationService = game:GetService("LocalizationService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local result, code = pcall(LocalizationService.GetCountryRegionForPlayerAsync, LocalizationService, player)
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
local GuiClone = script.OverheadGui:Clone()
GuiClone.Parent = Character.Head
local InformationLabel = GuiClone.InformationLabel
local PlayerRank = result
InformationLabel.Text = Player.Name .. ' - ' .. PlayerRank
end)
end)
Workspace.OverheadGui:17: attempt to concatenate string with boolean
Does anyone know how to fix this, I don’t know if I have made a huge mistake or have just done something simple.
I hope someone can help me out with this.
(Please reach out if you need extra information)
The first thing returned from pcall is a boolean dictating whether or not the function was run successfully, so you should be using code instead of result.
Since the error states that you are concatenating a string with a boolean, that must mean the Player.Rank property must be a boolean. Instead of defining the Player.Rank with result, use code instead. If needed, parse it into a string for concatenation
Hey so I did what you said and it makes the username part work, but i get this instead
When I tried local PlayerRank = string(code)
I get the error Workspace.OverheadGui:16: attempt to call a table value
I have no idea what to do so it would be great if anyone could help!
local LocalizationService = game:GetService("LocalizationService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local result, code = pcall(LocalizationService.GetCountryRegionForPlayerAsync, LocalizationService, player)
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
local GuiClone = script.OverheadGui:Clone()
GuiClone.Parent = Character.Head
local InformationLabel = GuiClone.InformationLabel
local PlayerRank = code
InformationLabel.Text = Player.Name .. ' - ' .. PlayerRank
end)
end)