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

attempt to index nil with 'Clone'? Help me why?

Asked by 4 years ago

We spawn or respawn i should get 3 random weapon

ServerScriptService.Script:21: attempt to index nil with 'Clone'

Stack Begin Script 'ServerScriptService.Script', Line 21 - function onCharacterAdded Stack End

local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Folder = RS:WaitForChild("Folder")

local function onCharacterAdded(character)
    local Tools = Folder:GetChildren()
    local ToolsTable = Tools
    local chosenTools = {}

    repeat
        local selectedIndex = math.random(1, #ToolsTable)
        table.insert(chosenTools, ToolsTable[selectedIndex])
        table.remove(ToolsTable, selectedIndex)
    until #chosenTools >= 3
    -- Numbers of tools going to give

    local plr = Players:GetPlayerFromCharacter(character)
    for i = 1, 4, 1 do
        print(i) -- Index
        print(chosenTools[i]) -- Tools
        local ToolsCloned = Folder:FindFirstChild(chosenTools[i]):Clone()
        ToolsCloned.Parent = plr.Backpack
    end
end

local function onAdded(player)
    player.CharacterAdded:Connect(onCharacterAdded) -- Triggers when the player spawns or respawns
end

Players.PlayerAdded:Connect(onAdded)
0
Well, as far as I cane tell, your script is not finding anything in the folder to clone. You can also check that by adding an if statement that says if Folder:FindFirstChild(chosenTools[i]) then print("Found") else print("not found thus there is nothing to clone") end AntoninFearless 622 — 4y
0
Well i did that and it says Found but still not working LikuLiku75 -1 — 4y

Answer this question