So im trying to do a Country Selection system for my game. Before, i only used Local Scripts, which was a bad idea because i wanted to hide the button on which the player click for everyone and its only hiding for the player himself. Then i rewrited the script and there is multiple errors.
Let me give you the scripts :
Module Script :
local CountryData = {
Countries = {
France = { Name = "France", Flag = game.Workspace.CountryData.France.Data.FlagID.Value, IsVisible = true },
Germany = { Name = "Germany", Flag = game.Workspace.CountryData.Germany.Data.FlagID.Value, IsVisible = true }
-- there is more country...
}
}
if CountryData.countries then
print("[ModuleScript] Loaded countries successfully.")
else
warn("[ModuleScript] ERROR: Countries table is NIL!")
end
return CountryData
Script :
local ServerStorage = game.ServerStorage
local countryModule = require(ServerStorage:WaitForChild("CountriesHandler"))
local InGameFunctions = game.ReplicatedStorage.InGameFunctions
local CountriesFunctions = InGameFunctions.CountriesFunctions
local playButtonEvent = CountriesFunctions.PlayButtonEvent
local hideButtonsEvent = CountriesFunctions.HideButtonsEvent
local countryDataEvent = CountriesFunctions.CountryDataEvent
playButtonEvent.OnServerEvent:Connect(function()
hideButtonsEvent:FireAllClients()
end)
game.Players.PlayerAdded:Connect(function(player)
countryDataEvent:FireClient(player, countryModule)
end)
LocalScript :
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local countryDataEvent = ReplicatedStorage.InGameFunctions.CountriesFunctions:WaitForChild("CountryDataEvent") -- Get the RemoteEvent
local hideButtonsEvent = ReplicatedStorage.InGameFunctions.CountriesFunctions:WaitForChild("HideButtonsEvent") -- Get the RemoteEvent
local playButtonEvent = ReplicatedStorage.InGameFunctions.CountriesFunctions:WaitForChild("PlayButtonEvent") -- Get the RemoteEvent
local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local gameGui = playerGui:WaitForChild("GameGui")
local firstFrame = gameGui:WaitForChild("FirstFrame")
local countryListFrame = firstFrame:WaitForChild("ScrollingChoosingFrame")
local sampleButton = countryListFrame:WaitForChild("Sample")
sampleButton.Visible = false
countryDataEvent.OnClientEvent:Connect(function(countries)
for _, country in pairs(countries) do
local countryButton = sampleButton:Clone()
countryButton.Text = country.Name
countryButton.Visible = true
countryButton.Flag.Image = country.Flag
countryButton.Parent = countryListFrame
end
end)
hideButtonsEvent.OnClientEvent:Connect(function()
for _, button in pairs(countryListFrame:GetChildren()) do
if button:IsA("TextButton") and button.Name ~= "Sample" then
button.Visible = false
end
end
end)
local playButton = firstFrame:WaitForChild("PlayButton")
playButton.MouseButton1Click:Connect(function()
playButtonEvent:FireServer()
end)
countryDataEvent:FireServer()
Output :
So here is the problem, and the second thing is that, its not cloning the buttons.
Any ideas how do i fix this ?