Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[FIXED] Script isn't inserting the player. How do I fix it?

Asked by
Ieowyyn 69
4 years ago
Edited 4 years ago

This question has been solved by the original poster.
01--// variables //--
02local debounce = false
03local placement = script.Parent.Parent.Values.Placings
04local amount = game.ReplicatedStorage.Values.Amount
05local finished = {}
06local finishedplrs = {}
07 
08--// touched script //--
09script.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
View all 31 lines...
1print(plr.Name)

works (line 16) but

1print(finished[1] .. " - " .. finishedplrs[1])

doesn't work. (line 23)

0
so i found out that the script isn't inserting neither of them Ieowyyn 69 — 4y
0
yes MemezyDev 172 — 4y

1 answer

Log in to vote
0
Answered by
Ieowyyn 69
4 years ago

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
11else
12    table.insert(finished, 1, plr.leaderstats.Team.Value)
13    table.insert(finishedplrs, 1, plr.Name)
14    print(finishedplrs[1] .. ": " .. finished[1])
15end
Ad

Answer this question