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.
--// variables //--
local debounce = false
local placement = script.Parent.Parent.Values.Placings
local amount = game.ReplicatedStorage.Values.Amount
local finished = {}
local finishedplrs = {}

--// touched script //--
script.Parent.Touched:Connect(function(hit)
    if debounce == false then
        debounce = true
        if hit.Parent:FindFirstChild("Humanoid") then
            if game.Players:FindFirstChild(hit.Parent.Name) then
                local plr = game.Players:FindFirstChild(hit.Parent.Name)
                if plr.TeamColor == BrickColor.new("Dusty Rose") then
                    print(plr.Name)
                    for i, v in pairs(finishedplrs) do
                        if v.Name == plr.Name then
                            print(plr.Name .. " already finished.")
                        else
                            table.insert(finished, 1, plr.leaderstats.Team.Value)
                            table.insert(finishedplrs, 1, plr.Name)
                            print(finished[1] .. " - " .. finishedplrs[1])
                        end
                    end
                    local debounce = false
                end
            end
        end
    end
end)
print(plr.Name)

works (line 16) but

print(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.

                            for i, v in pairs(finishedplrs) do
                                print("Checking player: " .. plr.Name)
                                if v.Name == plr.Name then
                                    print(plr.Name .. " already finished.")
                            else
                                table.insert(finished, 1, plr.leaderstats.Team.Value)
                                table.insert(finishedplrs, 1, plr.Name)
                                print(finishedplrs[1] .. ": " .. finished[1])
                                end
                            end
                        else
                            table.insert(finished, 1, plr.leaderstats.Team.Value)
                            table.insert(finishedplrs, 1, plr.Name)
                            print(finishedplrs[1] .. ": " .. finished[1])
                        end
Ad

Answer this question