01 | --// variables //-- |
02 | local debounce = false |
03 | local placement = script.Parent.Parent.Values.Placings |
04 | local amount = game.ReplicatedStorage.Values.Amount |
05 | local finished = { } |
06 | local finishedplrs = { } |
07 |
08 | --// touched script //-- |
09 | script.Parent.Touched:Connect( function (hit) |
10 | if debounce = = false then |
11 | debounce = true |
12 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
13 | if game.Players:FindFirstChild(hit.Parent.Name) then |
14 | local plr = game.Players:FindFirstChild(hit.Parent.Name) |
15 | if plr.TeamColor = = BrickColor.new( "Dusty Rose" ) then |
1 | print (plr.Name) |
works (line 16) but
1 | print (finished [ 1 ] .. " - " .. finishedplrs [ 1 ] ) |
doesn't work. (line 23)
Alright, I fixed it. Firstly, I completely forgot that in pairs() loops only loop for how many things are in a table. So first, I check whether something's inside. If it isn't there, it adds it in. If something Is there, it will check if it was already there. If not, then it will insert it in.
01 | for i, v in pairs (finishedplrs) do |
02 | print ( "Checking player: " .. plr.Name) |
03 | if v.Name = = plr.Name then |
04 | print (plr.Name .. " already finished." ) |
05 | else |
06 | table.insert(finished, 1 , plr.leaderstats.Team.Value) |
07 | table.insert(finishedplrs, 1 , plr.Name) |
08 | print (finishedplrs [ 1 ] .. ": " .. finished [ 1 ] ) |
09 | end |
10 | end |
11 | else |
12 | table.insert(finished, 1 , plr.leaderstats.Team.Value) |
13 | table.insert(finishedplrs, 1 , plr.Name) |
14 | print (finishedplrs [ 1 ] .. ": " .. finished [ 1 ] ) |
15 | end |