alright im going to test what i just copied from you
well i mean it doesnt work lmao
can you please send that in a message i am not copying that
script.Parent.MouseButton1Click:Connect(function()
local Localization = game:GetService("LocalizationService")
local CountryFlag = script.Parent.Parent.Parent.CountryFlag
--how do i get the player that is associated from the text button??
local result, code = pcall(function()
return Localization:GetCountryRegionForPlayerAsync() -- the player
end)
if code == "DK" then
CountryFlag.Image = "rbxassetid://105525969"
elseif code == "US" then
CountryFlag.Image = "rbxassetid://941761111"
elseif code == "GB" then
CountryFlag.Image = "rbxassetid://1064519589"
elseif code == "CA" then
CountryFlag.Image = "rbxassetid://82688846"
elseif code == "AF" then
CountryFlag.Image = "rbxassetid://10780313262"
elseif code == "AX" then
CountryFlag.Image = "rbxassetid://6924391098"
elseif code == "AL" then
CountryFlag.Image = "rbxassetid://82690675"
elseif code == "DZ" then
CountryFlag.Image = "rbxassetid://6924404634"
elseif code == "AS" then
CountryFlag.Image = "rbxassetid://9583261608"
elseif code == "AD" then
CountryFlag.Image = "rbxassetid://11002315718"
elseif code == "AO" then
CountryFlag.Image = "rbxassetid://7964310035"
elseif code == "AI" then
CountryFlag.Image = "rbxassetid://5933252830"
elseif code == "AQ" then
CountryFlag.Image = "rbxassetid://754202418"
elseif code == "AG" then
CountryFlag.Image = "rbxassetid://8457730273"
elseif code == "AR" then
CountryFlag.Image = "rbxassetid://6473879287"
elseif code == "AM" then
CountryFlag.Image = "rbxassetid://82206853"
elseif code == "AW" then
CountryFlag.Image = "rbxassetid://5577307956"
elseif code == "AU" then
CountryFlag.Image = "rbxassetid://11240147545"
elseif code == "AT" then
CountryFlag.Image = "rbxassetid://11150746432"
elseif code == "AZ" then
CountryFlag.Image = "rbxassetid://1386997103"
elseif code == "BS" then
CountryFlag.Image = "rbxassetid://82691369"
elseif code == "BH" then
CountryFlag.Image = "rbxassetid://82691389"
elseif code == "BD" then
CountryFlag.Image = "rbxassetid://82691427"
elseif code == "BB" then
CountryFlag.Image = "rbxassetid://82691455"
elseif code == "BY" then
CountryFlag.Image = "rbxassetid://116455774"
elseif code == "BE" then
CountryFlag.Image = "rbxassetid://5575222552"
elseif code == "BZ" then
CountryFlag.Image = "rbxassetid://8448856638"
elseif code == "BJ" then
CountryFlag.Image = "rbxassetid://1386975782"
elseif code == "BM" then
CountryFlag.Image = "rbxassetid://1387211575"
elseif code == "BT" then
CountryFlag.Image = "rbxassetid://10510329400"
elseif code == "BR" then
CountryFlag.Image = "rbxassetid://7750763178"
elseif code == "BG" then
CountryFlag.Image = "rbxassetid://5680144313"
elseif code == "KH" then
CountryFlag.Image = "rbxassetid://10778433472"
elseif code == "CL" then
CountryFlag.Image = "rbxassetid://9033083033"
elseif code == "CN" then
CountryFlag.Image = "rbxassetid://9110900644"
elseif code == "CO" then
CountryFlag.Image = "rbxassetid://6035329148"
elseif code == "CG" then
CountryFlag.Image = "rbxassetid://4450483599"
elseif code == "CW" then
CountryFlag.Image = "rbxassetid://8009479655"
elseif code == "CY" then
CountryFlag.Image = "rbxassetid://5339301368"
elseif code == "CZ" then
CountryFlag.Image = "rbxassetid://10868614622"
elseif code == "DJ" then
CountryFlag.Image = "rbxassetid://8439481652"
elseif code == "DM" then
CountryFlag.Image = "rbxassetid://4985213898"
elseif code == "DO" then
CountryFlag.Image = "rbxassetid://7705114675"
elseif code == "EC" then
CountryFlag.Image = "rbxassetid://5897221111"
elseif code == "EG" then
CountryFlag.Image = "rbxassetid://2408242658"
elseif code == "SV" then
CountryFlag.Image = "rbxassetid://2738109367"
elseif code == "ET" then
CountryFlag.Image = "rbxassetid://7828341313"
elseif code == "FJ" then
CountryFlag.Image = "rbxassetid://16820948"
elseif code == "FI" then
CountryFlag.Image = "rbxassetid://9631217519"
elseif code == "FR" then
CountryFlag.Image = "rbxassetid://3226406056"
elseif code == "GE" then
CountryFlag.Image = "rbxassetid://82206392"
elseif code == "DE" then
CountryFlag.Image = "rbxassetid://10031882093"
elseif code == "GR" then
CountryFlag.Image = "rbxassetid://3149186217"
elseif code == "GL" then
CountryFlag.Image = "rbxassetid://1027647421"
elseif code == "HK" then
CountryFlag.Image = "rbxassetid://116839240"
elseif code == "HU" then
CountryFlag.Image = "rbxassetid://10845803274"
elseif code == "IS" then
CountryFlag.Image = "rbxassetid://11002334472"
elseif code == "IN" then
CountryFlag.Image = "rbxassetid://136163916"
elseif code == "ID" then
CountryFlag.Image = "rbxassetid://9505068937"
elseif code == "IE" then
CountryFlag.Image = "rbxassetid://10194125708"
elseif code == "JP" then
CountryFlag.Image = "rbxassetid://5760720814"
elseif code == "KR" then
CountryFlag.Image = "rbxassetid://7199539762"
elseif code == "LU" then
CountryFlag.Image = "rbxassetid://11181902554"
elseif code == "LI" then
CountryFlag.Image = "rbxassetid://120568041"
elseif code == "MY" then
CountryFlag.Image = "rbxassetid://6214340412"
elseif code == "MX" then
CountryFlag.Image = "rbxassetid://10760076480"
elseif code == "MM" then
CountryFlag.Image = "rbxassetid://11226615898"
elseif code == "NL" then
CountryFlag.Image = "rbxassetid://5243374959"
elseif code == "NZ" then
CountryFlag.Image = "rbxassetid://8392099305"
elseif code == "NO" then
CountryFlag.Image = "rbxassetid://624478595"
elseif code == "PA" then
CountryFlag.Image = "rbxassetid://10880142719"
elseif code == "PH" then
CountryFlag.Image = "rbxassetid://9418075318"
elseif code == "PL" then
CountryFlag.Image = "rbxassetid://9124778742"
elseif code == "QA" then
CountryFlag.Image = "rbxassetid://23538968"
elseif code == "SG" then
CountryFlag.Image = "rbxassetid://118344191"
elseif code == "ZA" then
CountryFlag.Image = "rbxassetid://10802610604"
elseif code == "CH" then
CountryFlag.Image = "rbxassetid://6035302756"
elseif code == "TR" then
CountryFlag.Image = "rbxassetid://3104073690"
elseif code == "NP" then
CountryFlag.Image = "rbxassetid://5661746023"
end
end
end
end)
My script is a little different to yours but it works just fine! also i would recommend storing the flags in a module.
local frame = script.Parent.Frame
local scrollingframe = frame.ScrollingFrame
local template = scrollingframe.Temp
template.Visible = false
function clearitems()
for _,items in pairs(scrollingframe:GetChildren()) do
if items:IsA("TextButton") and items.Name ~= "Temp" then
items:Destroy()
end
end
end
function FillList()
clearitems()
for _, player in pairs(game:GetService("Players"):GetPlayers()) do
if not scrollingframe:FindFirstChild(player.Name) then
local new = template:Clone()
new.Name = player.Name
new.Text = player.Name
new.Parent = scrollingframe
new.Visible = true
new.Activated:Connect(function()
local Localization = game:GetService("LocalizationService")
local CountryFlag = script.Parent.Frame.ImageLabel
local player = game.Players:FindFirstChild(new.Name)
if not player then return end
local code = Localization:GetCountryRegionForPlayerAsync(player)
if code == "DK" then
CountryFlag.Image = "rbxassetid://105525969"
elseif code == "US" then
CountryFlag.Image = "rbxassetid://941761111"
elseif code == "GB" then
CountryFlag.Image = "rbxassetid://1064519589"
elseif code == "CA" then
CountryFlag.Image = "rbxassetid://82688846"
elseif code == "AF" then
CountryFlag.Image = "rbxassetid://10780313262"
elseif code == "AX" then
CountryFlag.Image = "rbxassetid://6924391098"
elseif code == "AL" then
CountryFlag.Image = "rbxassetid://82690675"
elseif code == "DZ" then
CountryFlag.Image = "rbxassetid://6924404634"
elseif code == "AS" then
CountryFlag.Image = "rbxassetid://9583261608"
elseif code == "AD" then
CountryFlag.Image = "rbxassetid://11002315718"
elseif code == "AO" then
CountryFlag.Image = "rbxassetid://7964310035"
elseif code == "AI" then
CountryFlag.Image = "rbxassetid://5933252830"
elseif code == "AQ" then
CountryFlag.Image = "rbxassetid://754202418"
elseif code == "AG" then
CountryFlag.Image = "rbxassetid://8457730273"
elseif code == "AR" then
CountryFlag.Image = "rbxassetid://6473879287"
elseif code == "AM" then
CountryFlag.Image = "rbxassetid://82206853"
elseif code == "AW" then
CountryFlag.Image = "rbxassetid://5577307956"
elseif code == "AU" then
CountryFlag.Image = "rbxassetid://11240147545"
elseif code == "AT" then
CountryFlag.Image = "rbxassetid://11150746432"
elseif code == "AZ" then
CountryFlag.Image = "rbxassetid://1386997103"
elseif code == "BS" then
CountryFlag.Image = "rbxassetid://82691369"
elseif code == "BH" then
CountryFlag.Image = "rbxassetid://82691389"
elseif code == "BD" then
CountryFlag.Image = "rbxassetid://82691427"
elseif code == "BB" then
CountryFlag.Image = "rbxassetid://82691455"
elseif code == "BY" then
CountryFlag.Image = "rbxassetid://116455774"
elseif code == "BE" then
CountryFlag.Image = "rbxassetid://5575222552"
elseif code == "BZ" then
CountryFlag.Image = "rbxassetid://8448856638"
elseif code == "BJ" then
CountryFlag.Image = "rbxassetid://1386975782"
elseif code == "BM" then
CountryFlag.Image = "rbxassetid://1387211575"
elseif code == "BT" then
CountryFlag.Image = "rbxassetid://10510329400"
elseif code == "BR" then
CountryFlag.Image = "rbxassetid://7750763178"
elseif code == "BG" then
CountryFlag.Image = "rbxassetid://5680144313"
elseif code == "KH" then
CountryFlag.Image = "rbxassetid://10778433472"
elseif code == "CL" then
CountryFlag.Image = "rbxassetid://9033083033"
elseif code == "CN" then
CountryFlag.Image = "rbxassetid://9110900644"
elseif code == "CO" then
CountryFlag.Image = "rbxassetid://6035329148"
elseif code == "CG" then
CountryFlag.Image = "rbxassetid://4450483599"
elseif code == "CW" then
CountryFlag.Image = "rbxassetid://8009479655"
elseif code == "CY" then
CountryFlag.Image = "rbxassetid://5339301368"
elseif code == "CZ" then
CountryFlag.Image = "rbxassetid://10868614622"
elseif code == "DJ" then
CountryFlag.Image = "rbxassetid://8439481652"
elseif code == "DM" then
CountryFlag.Image = "rbxassetid://4985213898"
elseif code == "DO" then
CountryFlag.Image = "rbxassetid://7705114675"
elseif code == "EC" then
CountryFlag.Image = "rbxassetid://5897221111"
elseif code == "EG" then
CountryFlag.Image = "rbxassetid://2408242658"
elseif code == "SV" then
CountryFlag.Image = "rbxassetid://2738109367"
elseif code == "ET" then
CountryFlag.Image = "rbxassetid://7828341313"
elseif code == "FJ" then
CountryFlag.Image = "rbxassetid://16820948"
elseif code == "FI" then
CountryFlag.Image = "rbxassetid://9631217519"
elseif code == "FR" then
CountryFlag.Image = "rbxassetid://3226406056"
elseif code == "GE" then
CountryFlag.Image = "rbxassetid://82206392"
elseif code == "DE" then
CountryFlag.Image = "rbxassetid://10031882093"
elseif code == "GR" then
CountryFlag.Image = "rbxassetid://3149186217"
elseif code == "GL" then
CountryFlag.Image = "rbxassetid://1027647421"
elseif code == "HK" then
CountryFlag.Image = "rbxassetid://116839240"
elseif code == "HU" then
CountryFlag.Image = "rbxassetid://10845803274"
elseif code == "IS" then
CountryFlag.Image = "rbxassetid://11002334472"
elseif code == "IN" then
CountryFlag.Image = "rbxassetid://136163916"
elseif code == "ID" then
CountryFlag.Image = "rbxassetid://9505068937"
elseif code == "IE" then
CountryFlag.Image = "rbxassetid://10194125708"
elseif code == "JP" then
CountryFlag.Image = "rbxassetid://5760720814"
elseif code == "KR" then
CountryFlag.Image = "rbxassetid://7199539762"
elseif code == "LU" then
CountryFlag.Image = "rbxassetid://11181902554"
elseif code == "LI" then
CountryFlag.Image = "rbxassetid://120568041"
elseif code == "MY" then
CountryFlag.Image = "rbxassetid://6214340412"
elseif code == "MX" then
CountryFlag.Image = "rbxassetid://10760076480"
elseif code == "MM" then
CountryFlag.Image = "rbxassetid://11226615898"
elseif code == "NL" then
CountryFlag.Image = "rbxassetid://5243374959"
elseif code == "NZ" then
CountryFlag.Image = "rbxassetid://8392099305"
elseif code == "NO" then
CountryFlag.Image = "rbxassetid://624478595"
elseif code == "PA" then
CountryFlag.Image = "rbxassetid://10880142719"
elseif code == "PH" then
CountryFlag.Image = "rbxassetid://9418075318"
elseif code == "PL" then
CountryFlag.Image = "rbxassetid://9124778742"
elseif code == "QA" then
CountryFlag.Image = "rbxassetid://23538968"
elseif code == "SG" then
CountryFlag.Image = "rbxassetid://118344191"
elseif code == "ZA" then
CountryFlag.Image = "rbxassetid://10802610604"
elseif code == "CH" then
CountryFlag.Image = "rbxassetid://6035302756"
elseif code == "TR" then
CountryFlag.Image = "rbxassetid://3104073690"
elseif code == "NP" then
CountryFlag.Image = "rbxassetid://5661746023"
end
end)
end
end
end
FillList()
game.Players.PlayerAdded:Connect(FillList)
game.Players.PlayerRemoving:Connect(clearitems)
is it all inside the PlayerList script?
in the script that makes all the buttons.
Best to utilise loops, make an array with all the IDs as values and the countries as Keys, then use a pairs loop
local flags = {
--// Flags
ExampleName = "Example ID"
}
local plrCountry = ""
local flagID: string = ""
for countryName: string, countryFlagID: string in pairs(flags) do
if countryName ~= plrCountry then continue end
flagID = countryFlagID
end
--// Continue
The following library/module seems very useful for what you’re trying to achieve:
I did kinda say that but i said to use a module to store them instead.
if only i didnt already help him
Sorry I didn’t see I was writing the code in studio lol
nope, it doesnt set the image with the id when i click the button
it works for me look at the video attached
how does it work for u, wait lemme check if theres italy flag
ahhhhh theres not the italy flag, that my bad, thank you for the help
Just to note for everyone here:
The suggestions you’ve had so far have been pretty good, but I would recommend you reconsider using multiple individual images - you’d be better off using spritesheets. You can either create that yourself, or you could look online for a resource, e.g. this CC0 country flag spritesheet here.
This would require very few changes to your current code, but would reduce the amount of HTTP
requests to load each individual image asset - not to mention that these images likely don’t have to be very big, so we’re wasting memory by throwing them into individual images.
The biggest change would be that, instead of setting the Image
property, you’d set the ImageRectSize
and ImageRectOffset
of the ImageLabel
- you’ll be able to find a few resources about this on the DevForum, I’m sure.
e.g. in the case of some of the examples here:
Note: This is example code - you’ll have to make some changes to make it function
-- in some ImageAssets.lua module
return {
ImageId = 'rbxassetid://the/spritesheet/image/id',
Flags = {
UK = { ImageRectOffset = Vector2.new(0, 0), ImageRectSize = Vector2.new(15, 15) }
-- ... todo: the other rect offsets + sizes from the image you've uploaded
}
}
-- in some ui code
local FlagImageAssets = require(the.image.asset.module)
local LocalizationService = game:GetService('LocalizationService')
local countryCode = LocalizationService:GetCountryRegionForPlayerAsync(player)
local details = countryCode and FlagImageAssets.Flags[countryCode] or nil
if not details then
-- couldn't find the flag, handle this case somehow
return
end
someFlagImageLabel.ImageRectOffset = details.ImageRectOffset
someFlagImageLabel.ImageRectSize = details.ImageRectSize
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.