There are honestly a lot of alternatives you could go around with this here, are you just specifically looking for a way to check the first winner of the minigame, along with obtaining every Player that’s currently playing to teleport? If so, let’s start out with your loop here
With this line here, you’re attempting to find a String datatype with a table full of Instances hence why that error occurs, where you should instead be doing, is using GetPartsInPart instead to detect a Box Collision within its radius
This function here, requires 2 parameters to pass through which will then return back as a Table of BaseParts so we can check
local DetectBox = workspace.SquidGame:WaitForChild("DetectBox")
local Params = OverlapParams.new()
Params.FilterType = Enum.RaycastFilterType.Blacklist
Params.FilterDescendantsInstances = {DetectBox}
local CurrentParts = workspace:GetPartsInPart(DetectBox, Params)
-- This will return back a Table of BaseParts that are currently colliding with the Box
Next, we’d want to go ahead and loop through our CurrentParts
table cause we want to see if our Parts are specified Parents of Character, and we can call the GetPlayerFromCharacter function to return back as a Player Instance
But keep in mind! We do not want to add multiple Tags, so we create another table which will hold all of the Players that we’ve already searched for, and ignore lines of code if we’ve already confirmed that they’re within that table
- We use
table.find()
to check if a BasePart’s Parent is equal to our Character to prevent duplication
- We use
table.insert()
to add a value into our Table after confirming
local PlayingPlayers = {}
for _, Part in pairs(CurrentParts) do
local Target = Part.Parent
if not Target then return end
local Plr = game.Players:GetPlayerFromCharacter(Target)
local DuplicateCheck = table.find(PlayingPlayers, Target)
if Plr and DuplicateCheck == nil then
table.insert(DuplicateCheck, Target)
local Tag = Instance,new("BoolValue")
Tag.Name = "playing"
Tag.Parent = Plr
end
end
Next up, is your ClickDetector
function here:
You can create something that’s called a debounce which only fires once the moment it activates, and cannot fire again until you re-define it back
local Debounce = false
Debounce = true
task.wait(1)
if Debounce == true then
print("Debounce is equal to true, so we already know this fired!")
else
print("Debounce is equal to false, that means no one has fired it yet!")
end
Within your Script I’d assume, you can implement a simple sanity check to see if debounce == true
if it’s already been run or not to guarantee a certified winner
local Debounce = false
local Part = script.Parent
local function Clicked(Plr)
if Debounce == true then return end
-- Debounce == false would mean it can be fired
-- Debounce == true would mean the function would cancel, and would only run if Debounce is back equal to "fase"
Debounce = true -- We set this to true so that our if statement above doesn't run again
local Winner = Instance.new("BoolValue")
Winner.Name = "winner"
Winner.Parent = Plr
print("The round has ended, and we have a winner,", Plr.."!")
end
Part.ClickDetector.MouseClick:Connect(Clicked)
And if you want to check when the round is over, you could create a Bool Value within your game that’ll check if the game is over or not to reset everything back to square one!
Something like this could do nicely:
local GameEnd = workspace:WaitForChild("GameEnded") -- This is a Bool
local playing -- Whatever you define playing as
while GameEnd.Value == false and playing > 0 do -- This will run until 1 of the 2 arguments have not been met
task.wait(1)
end
print("Game has ended!")
Of course, these are all just broad examples but hopefully you should have a better understanding on how to implement something like this
And do make sure to look more into the Documentation as well if you’re ever confused on anything!