So i have a few problems here:
1.) When a player1 or player2 wins player1 is always shown last in the table(when i test it in 2 player mode)
2.) I try to take the HotPotato away from the previous owner but it says its locked(alternative suggestions are appreciated.
3.) Ill provide more problems as the prioritized ones get answered first
Its alot of code so brace yourselfs.
ServerScript:
local function StartRound()
HotPotatoHolder = nil -- Hot potato holder to nil
if #PlayersInRound <= 1 then --Checks to make sure it start without having more than 2 players
print("has less than 2 players")
coroutine.wrap(function()
for _, v in pairs(Players:GetPlayers()) do
v.Character:MoveTo(LobbySpawn.Position)
v:FindFirstChild("InMatch").Value = false
end
end)()
table.clear(PlayersInRound)
matchoccuring = false
StartRound()
end
matchoccuring = true
InfoLabel.Text = "Players Remaining: "..#PlayersInRound
local timeleft
--Picking a random holder
HotPotatoHolder = PlayersInRound[math.random(1, #PlayersInRound)] --Picks Random player to start off with
--{Cloning Visual Effects & Tool}--
if HotPotatoHolder then
local HotPotato = game.ReplicatedStorage.HotPotato:Clone() --Clones Hot potato to parent to chosen one
HotPotato.Parent = HotPotatoHolder.Character
local Highlight = game.ReplicatedStorage.Highlight:Clone() --Clones Highlight to parent to chosen one
Highlight.Parent = HotPotatoHolder.Character
--{Touched Function}--
local char = HotPotatoHolder.Character
local canpass = true
coroutine.wrap(function()
for _, v in ipairs(char:GetChildren()) do
if v:IsA("BasePart") then
v.Touched:Connect(function(hit)
if hit:IsA("BasePart") and canpass then
local foundplr = game.Players:GetPlayerFromCharacter(hit.Parent)
if foundplr and foundplr ~= game.Players:GetPlayerFromCharacter(char) then
canpass = false
HotPotato.Parent = foundplr.Character
Highlight.Parent = foundplr.Character
HotPotatoHolder = foundplr
print(foundplr.Name)
task.wait(0.5)
canpass = true
end
end
end)
end
end
end)()
for i = 10, 0, -1 do --Counting down time with hot potato
timeleft = i
CountdownLabel.Text = "("..timeleft..")"
task.wait(1)
end
--{Killing the holder & removing from table when time's up}--
HotPotato:Destroy()
Highlight:Destroy()
HotPotatoHolder.Character:WaitForChild("Humanoid"):TakeDamage(999) --Kills current holder
HotPotatoHolder:WaitForChild("InMatch").Value = false --Sets their "InMatch" Bool to false
table.remove(PlayersInRound, PlayersInRound[HotPotatoHolder]) --Removes player from table
else
StartRound()
end
if #PlayersInRound > 1 then --If players is more than 1 then they restart the funtion
task.wait(0.75)
StartRound()
elseif #PlayersInRound <= 1 then --if its = or < then 1 then someone won
InfoLabel.Text = PlayersInRound[1].Name.." won the Round!!"
CountdownLabel.Text = "(...)"
task.wait(2.5)
for _, plr in pairs(Players:GetPlayers()) do
plr.Character:MoveTo(LobbySpawn.Position)
plr:WaitForChild("InMatch").Value = false
end
table.clear(PlayersInRound)
matchoccuring = false
end
end