You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I’m making a game and need to make a map voting section, and am now making it pick a random 3 maps, and display it on my ui. -
What is the issue? Include screenshots / videos if possible!
It’s printing what I scripted, but nothings changing with the UI.
Server Script:
--// Services \\--
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
--// Folders \\--
local MapsFolder = ReplicatedStorage:WaitForChild("Maps")
local RoundEvents = ReplicatedStorage:WaitForChild("RoundEvents")
--// Remote Events \\--
local PickMapsEvent = RoundEvents:WaitForChild("PickMapsEvent")
-- Function to select random maps and send data to clients
PickMapsEvent.OnServerEvent:Connect(function(player)
local maps = {}
-- Select 3 random maps
for i = 1, 3 do
local map = MapsFolder:GetChildren()[math.random(1, #MapsFolder:GetChildren())]
-- Create a map data table with Name and Image
table.insert(maps, {
Name = map.Name,
Image = map:GetAttribute("Image") -- Assuming you're storing image URLs in the "Image" attribute of maps
})
end
-- Debugging: print the selected maps and their attributes
print("Server: Selected maps:", maps)
-- Fire the event to all clients with the selected maps
PickMapsEvent:FireAllClients(maps)
end)
Local Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RoundEvents = ReplicatedStorage:WaitForChild("RoundEvents")
local PickMapsEvent = RoundEvents:WaitForChild("PickMapsEvent")
-- Listen for map data
PickMapsEvent.OnClientEvent:Connect(function(maps)
-- Debugging: Ensure the maps data is received correctly
print("Client: Received maps data", maps)
-- Handle the UI update (assume your voting frame is ready)
local VotingFrame = game.Players.LocalPlayer.PlayerGui.RoundInfo.Voting
if not VotingFrame then
print("Error: VotingFrame is not found!")
return
end
-- Check if we have map frames to update
local mapFrames = VotingFrame:GetChildren()
if #mapFrames == 0 then
print("Error: No map frames found inside VotingFrame!")
return
end
-- Debugging: print the names of map frames in the Voting frame
for _, frame in ipairs(mapFrames) do
print("Map Frame found:", frame.Name)
end
-- Assign maps to map options
for i, mapData in ipairs(maps) do
local mapFrame = mapFrames[i]
if mapFrame and mapFrame.Name ~= "UICorner" and mapFrame.Name ~= "Title" then
print("Updating frame:", mapFrame.Name) -- Debugging
local previewImage = mapFrame:FindFirstChild("Preview")
if previewImage then
previewImage.Image = mapData.Image
print("Set image to:", mapData.Image)
else
print("Error: Preview image not found in frame:", mapFrame.Name)
end
local mapName = mapFrame:FindFirstChild("MapName")
if mapName then
mapName.Text = mapData.Name
print("Set map name to:", mapData.Name)
else
print("Error: MapName label not found in frame:", mapFrame.Name)
end
end
end
end)
-- Check if the event listener is correctly set up
print("Client: Event Listener is active")
My explorer: