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

Why wont my this script distribute the swords to all players with a bool value true?

Asked by 6 years ago

This script is used to distribute swords from the replicated storage by cloning. What's happening is only one character is getting a sword, even though all bools in each character are perfect to receive swords.

I put prints everywhere and the prints in the output seemed to stop at the first for loop.

function InsertSwords()

    for i, v in pairs(game.Players:GetPlayers()) do
    local playersword = v:WaitForChild("PersonalSword")

    local replicated = game.ReplicatedStorage:GetChildren()

    if v.Ingame.Value == true and v.GameBool.Value == true then

        for i = 1, #replicated do
        if replicated[i].Name == playersword.Value then
        local scheduledsword = game.ReplicatedStorage:FindFirstChild(replicated[i].Name):Clone()
        scheduledsword.Parent = v.Backpack

        end
    end
    end

end

0
Here is 2 questions 1.Is this code in script or local script.2.Is this function being used like calling it InsertSwords() PlaasBoer 275 — 6y
0
1. It is a world script. 2. I don't know exactly what you mean by that, but the function is called InsertSwords() because that is what I want it to do. bigbenbennett 18 — 6y
0
Please Help bigbenbennett 18 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
local strg = game:GetService"ReplicatedStorage"

function giveSwords()
    for _, v in pairs(game:GetService("Players"):GetPlayers()) do
        local plrSword = v:WaitForChild"PersonalSword"
        local replicated = strg.Tools:GetChildren() -- i put them in a folder for tidyness

        if v.Ingame.Value == true and v.GameBool.Value == true then
            for _, child in pairs(replicated) do
                if child.Name = plrSword.Value then
                    local scheduled = strg:FindFirstChild(child.Name):Clone()
                    scheduled.Parent = v.Backpack
                    scheduled.Parent = v.StarterGear

                end
            end
        end
    end
end

delay(3.75, giveSwords)
0
I get the response: attempt to index a nil value for line 11 bigbenbennett 18 — 6y
Ad

Answer this question