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

attempt to index nil with 'Backpack'?

Asked by 4 years ago

So i have made a script where it gives a 10 second intermission before everyone is given a sword. Script goes like this:

t = 10
repeat
    s.Value = "You will be given a sword in "..t.." seconds, stay alive"
    wait(1)
    t = t -1
until t == 0
player = 1
local plrs = game.Players:GetChildren()
repeat
    local clone = game.ServerStorage.ClassicSword:Clone()
    clone.Parent = plrs[player].Backpack
    clone.Script.Disabled = false
    player = player +1
until player == #ingame
end

The line it errors on is line 11.

Anyone got a fix for this?

1 answer

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago
local serverStorage = game:GetService("ServerStoage")
local players = game:GetService("Players")

local swordTool = serverStorage.ClassicSword

local intermissionTime = 10

for secondsLeft = intermissionTime, 1, -1 do
    local secondFormat = (secondsLeft > 1 and "seconds" or "second")
    s.Value = "You will receive your sword in "..secondsLeft..' '..secondFormat.."; stay alive!"
end

for _,player in pairs(players:GetPlayers()) do
    local sword = swordTool:Clone()
    sword.Script.Disabled = false
    sword.Parent = player.Backpack
end
0
Thanks, but is there a way to just keep the code i currently have and just change some stuff in it to make it work? YelloMynamesZak 85 — 4y
0
Yes, but the code you're using is highly inefficient. Ziffixture 6913 — 4y
0
Nevermind, i got it to work. YelloMynamesZak 85 — 4y
Ad

Answer this question