Hello, i having issue when i tried make when someone voted then timer voting starts
I wouldn’t want to my friend joined in after half a match
if possible you can tell why it should work this way or why the error is happening
i’m newbie on scripting (sorry for bad grammar in the text I was so tired when was trying to fix this error)
script:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local BadgeService = game:GetService("BadgeService")
local badgeId = 0 -- id badge
local events = ReplicatedStorage:WaitForChild("Events")
local maxWave = 41
local mob = require(script.Parent.Mob)
local info = workspace.Info
local themes = workspace.Themes
local effect = game.Lighting
local round = {}
local votes = {}
function round.StartGame()
local map = round.LoadMap()
info.GameRunning.Value = true
for i= 15, 0, -1 do
info.Message.Value = "Game Starting in..." .. i
task.wait(1)
end
for wave= 1, maxWave do
info.Wave.Value = wave
info.Message.Value = ""
round.GetWave(wave, map)
repeat
task.wait(1.54)
until #workspace.Mobs:GetChildren() == 0 or not info.GameRunning.Value
if info.GameRunning.Value and wave == maxWave then
info.Message.Value = "VICTORY"
for _,player in pairs(game:GetService("Players"):GetPlayers()) do
BadgeService:AwardBadge(player.UserId,badgeId)
print(player .. " has win and got badge id: " .. badgeId)
end
elseif info.GameRunning.Value then
local reward = 45 * wave
for i, player in ipairs(Players:GetPlayers()) do
player.Money.Value += reward
end
info.Message.Value = "Round completion bonus: " .. reward
task.wait(2)
for i= 5, 0, -1 do
info.Message.Value = "" .. i
task.wait(1)
end
else
break
end
end
end
function round.LoadMap()
local votedMap = round.ToggleVoting()
local mapFolder = ServerStorage.Maps:FindFirstChild(votedMap) -- Error
if not mapFolder then
mapFolder = ServerStorage.Maps["House Map"]
end
local newMap = mapFolder:Clone()
newMap.Parent = workspace.Map
workspace.SpawnBox.Floor:Destroy()
newMap.Base.Humanoid.HealthChanged:Connect(function(health)
if health <= 0 then
info.GameRunning.Value = false
info.Message.Value = "GAME OVER"
end
end)
return newMap
end
function round.ToggleVoting()
local maps = ServerStorage.Maps:GetChildren()
votes = {}
for i, map in ipairs(maps) do
votes[map.Name] = {}
end
info.Voting.Value = true
--[[for i= 35, 1, -1 do
info.Message.Value = "Map voting (" .. i .. ")"
end
end
task.wait(1)]] -- Old Code
local winVote = nil
local WinScore = 0
for name, map in pairs(votes) do
if WinScore == 1 then -- new code
for i= 35, 1, -1 do
info.Message.Value = "Map voting (" .. i .. ")"
end
end
if #map > WinScore then
WinScore = #map
winVote = name
end
end
info.Voting.Value = false
return winVote
end
function round.ProcessVote(player, vote)
for name, mapVotes in pairs(votes) do
local oldVote = table.find(mapVotes, player.UserId)
if oldVote then
table.remove(mapVotes, oldVote)
print("Old vote found", oldVote )
break
end
end
print("Processed vote for", vote)
table.insert(votes[vote], player.UserId)
events:WaitForChild("UpdateVoteCount"):FireAllClients(votes)
end
events:WaitForChild("VoteForMap").OnServerEvent:Connect(round.ProcessVote)
function round.GetWave(wave, map)
if wave <= 1 then
mob.Spawn("Mobs", 1, map)
Output:
19:19:00.791 Stack Begin - Studio
19:19:00.791 Script 'ServerScriptService.Main.Round', Line 67 - function LoadMap - Studio - Round:67
19:19:00.791 Script 'ServerScriptService.Main.Round', Line 21 - function StartGame - Studio - Round:21
19:19:00.792 Script 'ServerScriptService.Main', Line 12 - Studio - Main:12
19:19:00.792 Stack End