Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

attempt to index nil with 'Backpack'?

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

✓ Accepted answer
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

3 comments

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?

0

Yes, but the code you're using is highly inefficient.

0

Nevermind, i got it to work.

This discussion is preserved as it was. New answers, comments, and votes are closed.