The main reason for this script is to determine the winner, but that's the only thing that it can't do. I've tried numerous times to find where the error is but the output doesn't come out with one. I don't know if anyone is even going to be willing to be reading all of the script which is why I held back on going to this option for so long but I hope it gets solved. Thanks in advance.
--// Variables
local Status = game.ReplicatedStorage.StatusValue
local PlayersAlive = game.ReplicatedStorage.PlayersAlive
--// Functions
function FindIndex(Table, Val)
for index, v in pairs(Table, Val) do
if v == Val then
return index
end
end
end
--//Main Script
local debounce = false
script.Parent.Touched:connect(function(hit)
local h = hit.Parent:FindFirstChild("Humanoid")
if h and debounce ~= true then
debounce = true
local a = hit.Parent.Name
workspace[a]:FindFirstChild("Torso").CFrame = CFrame.new(workspace.Lobby.Spawn.Position)
if game.ReplicatedStorage.Players:FindFirstChild(a) then game.ReplicatedStorage.Players:FindFirstChild(a):Destroy() end
PlayersAlive.Value = PlayersAlive.Value - #game.ReplicatedStorage.Players:GetChildren()
wait()
debounce = false
workspace.MapStorage:ClearAllChildren()
_G.RoundInProgress = false
elseif #game.ReplicatedStorage.Players:GetChildren() == 0 then
Status.Value = "Everybody has lost the game :("
workspace.MapStorage:ClearAllChildren()
_G.RoundInProgress = false
else return end
end)
game.ReplicatedStorage.PlayersAlive.Changed:connect(function()
if PlayersAlive.Value == 1 then
for i, v in pairs(game.ReplicatedStorage.PlayersAlive:GetChildren()) do
local a = v.Parent.Name
print(a)
if game.ReplicatedStorage:FindFirstChild(a) then
game.Players[a].leaderstats.Coins.Value = game.Players[a].leaderstats.Coins.Value + 200
game.Playres[a].leaderstats.Wins.Value = game.Players[a].leaderstats.Wins.Value + 1
Status.Value = a.. "has won the game!"
wait(1)
end
end
end
end)
