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:

01t = 10
02repeat
03    s.Value = "You will be given a sword in "..t.." seconds, stay alive"
04    wait(1)
05    t = t -1
06until t == 0
07player = 1
08local plrs = game.Players:GetChildren()
09repeat
10    local clone = game.ServerStorage.ClassicSword:Clone()
11    clone.Parent = plrs[player].Backpack
12    clone.Script.Disabled = false
13    player = player +1
14until player == #ingame
15end

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
01local serverStorage = game:GetService("ServerStoage")
02local players = game:GetService("Players")
03 
04local swordTool = serverStorage.ClassicSword
05 
06local intermissionTime = 10
07 
08for secondsLeft = intermissionTime, 1, -1 do
09    local secondFormat = (secondsLeft > 1 and "seconds" or "second")
10    s.Value = "You will receive your sword in "..secondsLeft..' '..secondFormat.."; stay alive!"
11end
12 
13for _,player in pairs(players:GetPlayers()) do
14    local sword = swordTool:Clone()
15    sword.Script.Disabled = false
16    sword.Parent = player.Backpack
17end
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