Sorry for the vague title but I'm not sure how to word this. I'm a novice scripter and this is my first post here so I apologize in advance for whatever might be wrong
I'm making a turn based combat game and I have this script that runs through all the players and AI to see who hasn't taken their turn, and then makes it their turn by changing their "Status" value (A string value that is supposed to be either "Waiting, Done, or Picking").
local remoteEvent = game.ReplicatedStorage:WaitForChild("Passturn") local Players = game:GetService("Players") function passturn(p) local char = p.Character local t = {} for i,v in pairs (char.Parent:GetChildren()) do t[#t+1] = Players:GetPlayerFromCharacter(v) -- add the players into the array end for i,v in pairs (char.Parent.Parent.AI:GetChildren()) do t[#t+1] = v -- add the AI into the array end print (t) for i,v in pairs(t) do local stat = v:FindFirstChild("Status") if stat.Value ~= ("Done") then stat.Value = "Picking" -- Find the first player who hasnt taken a turn and make it their turn break end end end remoteEvent.OnServerEvent:Connect(passturn)
This script works fine but only for one round. I'm looking for a way for the script to check if ALL player's statuses are "Done" and if so, restart by making it (t[1])'s turn and set everyone else's status to "Waiting"
This one isn't as important but I'd also like to sort the array by each player/AI's Speed stat. So that a player or NPC with a higher speed value will be closer to [1] in the array.
These are the first things I've come across that I cant wrap my head around and I just need someone to point me in the right direction so I can look up what to use. Once again I apologize for how messy my script might be and thanks in advance to any helpers