What do I mean by this? In some games, When you vote, Your player icon goes on the GUI
Don’t stress it. There is a table on the server.
You can add an ImageLabel to the map frame, randomize it’s position within the map frame, do this to get the player’s icon and finally set the ImageLabel’s Image property to the content
local plr = -- player
local thumtype = Enum.ThumbnailType.AvatarBust
local thumsize = Enum.ThumbnailSize.Size420x420
local content = game.Players:GetUserThumbnailAsync(plr.UserId, thumtype,thumsize)
-- content is player image
Please could you provide a script?
You can do this, if the player removes their vote just find the image label with their name and destroy it
local random = Random.new() -- rng
local ImageLabel = -- imageLabel inside ServerStorage to be cloned
local frame = -- location of your map frame
local function VoteChanged(player) -- run when you add player to plrVotes table
local thumtype = Enum.ThumbnailType.AvatarBust
local thumsize = Enum.ThumbnailSize.Size420x420
local PlayerIcon = game.Players:GetUserThumbnailAsync(player.UserId, thumtype,thumsize) -- plr image
local XScale = random.NextNumber(random,0.2,0.8) -- randomizes position
local YScale = random.NextNumber(random,0.2,0.8)
local Clone = ImageLabel:Clone()
Clone.Image = PlayerIcon
Clone.Position = UDim2.new(XScale, 0, YScale, 0)
Clone.Name = player.Name
Clone.Parent = frame
end
I think I said it wrong I just realised. Here is my existing script for the voting system.
Client:
local rs = game.ReplicatedStorage
local res = rs:WaitForChild("RemoteEvents")
local frame = script.Parent:WaitForChild("MapVoteFrame"); frame.Visible = false
local templateFrame = script:WaitForChild("MapFrame")
res:WaitForChild("VotingBegun").OnClientEvent:Connect(function(mapsToVote)
for _, child in pairs(frame:WaitForChild("MapsContainer"):GetChildren()) do
if child.ClassName == templateFrame.ClassName then
child:Destroy()
end
end
local mapFrames = {}
for _, map in pairs(mapsToVote) do
local newMapFrame = templateFrame:Clone()
newMapFrame.Name = map.Name
newMapFrame.MapName.Text = map.Name
newMapFrame.NumVotes.Text = "Votes: 0"
newMapFrame.VoteButton.Image = "rbxassetid://" .. map.Configuration.ImageId.Value
newMapFrame.VoteButton.MouseButton1Click:Connect(function()
res:WaitForChild("Voted"):FireServer(map.Name)
end)
table.insert(mapFrames, newMapFrame)
end
table.sort(mapFrames, function(a, b)
return a.Name < b.Name
end)
for _, mapFrame in pairs(mapFrames) do
mapFrame.Parent = frame.MapsContainer
end
frame.Visible = true
end)
res:WaitForChild("VotingEnded").OnClientEvent:Connect(function()
frame.Visible = false
end)
res:WaitForChild("Voted").OnClientEvent:Connect(function(plrVotes)
if frame.Visible == true then
local votes = {}
for plr, vote in pairs(plrVotes) do
if not votes[vote] then
votes[vote] = 1
else
votes[vote] += 1
end
end
for _, mapFrame in pairs(frame.MapsContainer:GetChildren()) do
if mapFrame.ClassName == templateFrame.ClassName then
mapFrame.NumVotes.Text = "Votes: " .. (votes[mapFrame.Name] or 0)
end
end
end
end)
Server:
local rs = game.ReplicatedStorage
local maps = rs:WaitForChild("Maps")
local res = rs:WaitForChild("RemoteEvents")
local numMapsVoting = 3
local intermissionTime = 20
local voteTime = 10
local plrVotes = {}
function addVote(plr:Player, mapName:string)
plrVotes[plr] = mapName
res:WaitForChild("Voted"):FireAllClients(plrVotes)
end
function removePlayerVote(plr:Player)
plrVotes[plr] = nil
res:WaitForChild("Voted"):FireAllClients(plrVotes)
end
function loadMap(mapName:string)
local newMap = maps[mapName]:Clone()
newMap.Parent = workspace
local spawns = newMap:WaitForChild("Spawns"):GetChildren()
for i, plr in pairs(game.Players:GetPlayers()) do
if plr.Character then
plr.Character.HumanoidRootPart.CFrame = (spawns[i] and spawns[i].CFrame or spawns[i-#spawns]) + Vector3.new(0, 10, 0)
end
end
return newMap
end
function removeMap(map:Instance)
map:Destroy()
for _, plr in pairs(game.Players:GetPlayers()) do
plr:LoadCharacter()
end
end
function handleRound()
local plrsAlive = {}
for _, plr in pairs(game.Players:GetPlayers()) do
if plr.Character and plr.Character.Humanoid.Health > 0 then
table.insert(plrsAlive, plr)
plr.Character.Humanoid.Died:Connect(function()
table.remove(plrsAlive, table.find(plrsAlive, plr))
end)
end
end
for i = 1, 20 do
task.wait(1)
if #plrsAlive == 0 then
break
end
end
task.wait(5)
end
res:WaitForChild("Voted").OnServerEvent:Connect(addVote)
game.Players.PlayerRemoving:Connect(removePlayerVote)
while true do
task.wait(intermissionTime)
local mapsToVote = maps:GetChildren()
while #mapsToVote > numMapsVoting do
table.remove(mapsToVote, math.random(1, #mapsToVote))
end
plrVotes = {}
res:WaitForChild("VotingBegun"):FireAllClients(mapsToVote)
task.wait(voteTime)
local highestVotedFor = nil
local votes = {}
for i, map in pairs(mapsToVote) do
votes[map.Name] = 0
if i == 1 then
highestVotedFor = map.Name
end
end
for plr, vote in pairs(plrVotes) do
if votes[vote] then
votes[vote] += 1
if votes[highestVotedFor] < votes[vote] then
highestVotedFor = vote
end
end
end
res:WaitForChild("VotingEnded"):FireAllClients()
local newMap = loadMap(highestVotedFor)
handleRound()
removeMap(newMap)
end
The server works fine. Here’s the updated script for the client:
local random = Random.new() -- rng
local ImageLabel -- add ImageLabel to ReplicatedStorage and link it here
local rs = game.ReplicatedStorage
local res = rs:WaitForChild("RemoteEvents")
local frame = script.Parent:WaitForChild("MapVoteFrame"); frame.Visible = false
local templateFrame = script:WaitForChild("MapFrame")
local thumtype = Enum.ThumbnailType.AvatarBust
local thumsize = Enum.ThumbnailSize.Size420x420
--Voting begun
--Voting ended
res:WaitForChild("Voted").OnClientEvent:Connect(function(plrVotes)
if frame.Visible == true then
local votes = {}
local Processed = {} -- people who voted
for plr, vote in pairs(plrVotes) do
if not votes[vote] then
votes[vote] = 1
else
votes[vote] += 1
end
local voteFrame = frame.MapsContainer:WaitForChild(vote) -- vote frame
local playerVoteExists = false
for i,v in pairs(voteFrame:GetChildren()) do -- finds player's image label
if v:IsA("ImageLabel") then
if v.Name == plr then
playerVoteExists = true
break
end
end
end
if playerVoteExists == false then -- player image doesn't exist, create it
local PlayerIcon = game.Players:GetUserThumbnailAsync(game.Players:FindFirstChild(plr).UserId, thumtype,thumsize) -- plr image
local XScale = random.NextNumber(random,0.2,0.8) -- randomizes position
local YScale = random.NextNumber(random,0.2,0.8)
local Clone = ImageLabel:Clone()
Clone.Image = PlayerIcon
Clone.Position = UDim2.new(XScale, 0, YScale, 0)
Clone.Name = plr
Clone.Parent = voteFrame
end
table.insert(Processed, plr)
end
for i,plr in pairs(game.Players:GetPlayers()) do -- find people who haven't voted
local hasNotVoted = true
for i, ProcessedPlr in pairs(Processed) do
if plr.Name == ProcessedPlr then
hasNotVoted = false
break
end
end
if hasNotVoted == true then -- player hasn't voted
for _, mapFrame in pairs(frame.MapsContainer:GetChildren()) do -- find frame and destroy it
for _, label in pairs(mapFrame:GetChildren()) do
if label:IsA("ImageLabel") and label.Name == plr.Name then
label:Destroy()
end
end
end
else -- find frame in other votes and destroy it if vote changes
for _, mapFrame in pairs(frame.MapsContainer:GetChildren()) do --
if mapFrame.Name == plrVotes[plr.Name] then continue end
for _, label in pairs(mapFrame:GetChildren()) do
if label:IsA("ImageLabel") and label.Name == plr.Name then
label:Destroy()
end
end
end
end
end
for _, mapFrame in pairs(frame.MapsContainer:GetChildren()) do
if mapFrame.ClassName == templateFrame.ClassName then
mapFrame.NumVotes.Text = "Votes: " .. (votes[mapFrame.Name] or 0)
end
end
end
end)
Let me know if it doesn’t work and tell me how it breaks
Sorry I thought the index was a string.
Here’s the updated script
if frame.Visible == true then
local votes = {}
local Processed = {} -- people who voted
for plr, vote in pairs(plrVotes) do
if not votes[vote] then
votes[vote] = 1
else
votes[vote] += 1
end
local voteFrame = frame.MapsContainer:WaitForChild(vote) -- vote frame
local playerVoteExists = false
for i,v in pairs(voteFrame:GetChildren()) do -- finds player's image label
if v:IsA("ImageLabel") then
if v.Name == plr.Name then
playerVoteExists = true
break
end
end
end
if playerVoteExists == false then -- player image doesn't exist, create it
local PlayerIcon = game.Players:GetUserThumbnailAsync(plr.UserId, thumtype,thumsize) -- plr image
local XScale = random.NextNumber(random,0.2,0.8) -- randomizes position
local YScale = random.NextNumber(random,0.2,0.8)
local Clone = ImageLabel:Clone()
Clone.Image = PlayerIcon
Clone.Position = UDim2.new(XScale, 0, YScale, 0)
Clone.Name = plr.Name
Clone.Parent = voteFrame
end
table.insert(Processed, plr)
end
for i,plr in pairs(game.Players:GetPlayers()) do -- find people who haven't voted
local hasNotVoted = true
for i, ProcessedPlr in pairs(Processed) do
if plr.Name == ProcessedPlr.Name then
hasNotVoted = false
break
end
end
if hasNotVoted == true then -- player hasn't voted
for _, mapFrame in pairs(frame.MapsContainer:GetChildren()) do -- find frame and destroy it
for _, label in pairs(mapFrame:GetChildren()) do
if label:IsA("ImageLabel") and label.Name == plr.Name then
label:Destroy()
end
end
end
else -- find frame in other votes and destroy it if vote changes
for _, mapFrame in pairs(frame.MapsContainer:GetChildren()) do --
if mapFrame.Name == plrVotes[plr.Name] then continue end
for _, label in pairs(mapFrame:GetChildren()) do
if label:IsA("ImageLabel") and label.Name == plr.Name then
label:Destroy()
end
end
end
end
end
for _, mapFrame in pairs(frame.MapsContainer:GetChildren()) do
if mapFrame.ClassName == templateFrame.ClassName then
mapFrame.NumVotes.Text = "Votes: " .. (votes[mapFrame.Name] or 0)
end
end
end
end)
lol
Umm where is that again I don’t know the line it errored
Hey sorry, I dont know if you saw you message or not. It is on line 83 where it errored.
Yeah it did print nil
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.