Hello scripters! I have been working on a new game that uses a round system. The script I have doesn’t work very well and I don’t know why. So I am wondering if I should redo the script entirely using a different method, or if you could help me find bugs.
Current Script
local status = game.ReplicatedStorage.Status
local gunStorage = game.ServerStorage.Guns
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local length = 30
local DataStore2 = require(game.ServerScriptService.Data.DataStore2)
while true do
status.Value = "Waiting for players..."
repeat wait(1) until Players.NumPlayers > 1
status.Value = "Intermission.."
local currentPlrs = {}
local pTable = Players:GetChildren()
local random1 = math.random(1,#pTable)
for i, v in pairs(pTable) do
if i == random1 then
table.insert(currentPlrs, i, v)
table.remove(pTable, i)
end
end
local random2 = math.random(1,#pTable)
for i, v in pairs(pTable) do
if i == random2 then
table.insert(currentPlrs, i, v)
table.remove(pTable, i)
end
end
wait(20)
status.Value = "Duel between "..currentPlrs[1].Name.." and "..currentPlrs[2].Name.." beginning..."
for i,v in pairs(currentPlrs) do
character = game.Workspace:FindFirstChild(v.Name)
local aSpawn = workspace.Spawns:FindFirstChild(i)
character:FindFirstChild("HumanoidRootPart").CFrame = aSpawn.CFrame
print(currentPlrs[1],currentPlrs[2], currentPlrs[3])
local newGun = gunStorage:FindFirstChild(v.gunSlot.Value):Clone(); newGun.Parent = v.Backpack
end
for i = length, 0, -1 do
for i, v in pairs(currentPlrs) do
v.character.Humanoid.Died:Connect(function()
table.remove(currentPlrs, i)
end)
end
if #currentPlrs == 1 then
status.Value = currentPlrs[1].Name.." has won!"
local moneyStore = DataStore2("money", currentPlrs[1])
moneyStore:Increment(10)
break
elseif #currentPlrs == 0 then
status.Value = "No one won :("
break
elseif i == 0 then
status.Value = "Time up."
end
end
end
If you see any noticeable bugs could you point them out. There are no errors in the output.