ранее уже выкладывал вопрос,это можно назвать его продолжением после некоторых поправок,которые я сделал по совету человека,который мне ответил,у меня получился скрипт,который покажу чуть ниже.Сейчас стоит сказать,что выскакивает ошибка ServerScriptService.Main.Round:87: invalid argument #1 to 'insert' (table expected, got nil) - Server - Round:87 строка 87 - строка где написано table.insert(votes[vote], player.UserId)
скрипт: local ServerStorage = game:GetService("ServerStorage") local ReplicatedStorage = game:GetService("ReplicatedStorage")
local events = ReplicatedStorage:WaitForChild("Events")
local info = workspace.Info
local round = {} local votes = {}
local mob = require(script.Parent.Mob)
function round.LoadMap() task.wait(2)
local votedMap = round.ToggleVoting() print("Voted map:", votedMap) -- Выводим имя выбранной карты
if not ServerStorage.Maps then error("Maps folder does not exist in ServerStorage") end local mapFolder = ServerStorage.Maps:FindFirstChild(votedMap) if not mapFolder then print("Map not found, using default GrassLand.") mapFolder = ServerStorage.Maps.GrassLand 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() for i = 10, 1, -1 do info.Message.Value = "Map voting (" .. i .. ")" print("Map voting (" .. i .. ")") task.wait(1) end
local maps = ServerStorage.Maps:GetChildren() for i, map in ipairs(maps) do votes[ map.Name ] = {} end
local winVote = nil local winScore = 0 for name, map in pairs(votes) do if #map > winScore then winScore = #map winVote = name end end
if not winVote then local n = math.random(#maps) winVote = maps[n].Name end
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)
скрипт:
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local events = ReplicatedStorage:WaitForChild("Events")
local info = workspace.Info
local round = {}
local votes = {}
local mob = require(script.Parent.Mob)
function round.LoadMap()
task.wait(2)
local votedMap = round.ToggleVoting()
print("Voted map:", votedMap) -- Выводим имя выбранной карты
if not ServerStorage.Maps then
error("Maps folder does not exist in ServerStorage")
end
local mapFolder = ServerStorage.Maps:FindFirstChild(votedMap)
if not mapFolder then
print("Map not found, using default GrassLand.")
mapFolder = ServerStorage.Maps.GrassLand
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()
for i = 10, 1, -1 do
info.Message.Value = "Map voting (" .. i .. ")"
print("Map voting (" .. i .. ")")
task.wait(1)
end
local maps = ServerStorage.Maps:GetChildren()
for i, map in ipairs(maps) do
votes[ map.Name ] = {}
end
local winVote = nil
local winScore = 0
for name, map in pairs(votes) do
if #map > winScore then
winScore = #map
winVote = name
end
end
if not winVote then
local n = math.random(#maps)
winVote = maps[n].Name
end
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()
end
events:WaitForChild("VoteForMap").OnServerEvent:Connect(round.ProcessVote)