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

What is wrong with my Tool-Giving script?

Asked by 10 years ago

I have conducted many tests, but nothing seems to be working, it keeps saying Workspace.GameScript:13: attempt to index field '?' (a nil value), I dont know what it means by that, nor what I did wrong, here is the whole script;

wait(5)

Hint=Instance.new("Hint")
newtools=script:GetChildren()
player=game.Players:GetChildren()

while workspace:FindFirstChild("PartThing")~=nil do 

for i= 1,#player do
if player[i].className=="Player"then
for i=1,#newtools do
if newtools[i].className=="HopperBin"then
newtools[i]:Clone().Parent=player[i].Backpack
end end end end

waitTime=300

repeat wait(1)waitTime=waitTime-1 until waitTime==0

if waitTime==0 then

players2=game.Players:GetChildren()
for i=1,#players do
if players[i].className~="Player"then return end
backpack=players[i].Backpack:GetChildren()
for i =1,#backpack do
if backpack[i].className=="HopperBin"then
backpack[i]:remove()

Hint.Parent=workspace
Hint.Text="Times up!"

wait(5)
Hint.Text="The Minions are coming! Prepare yourselves!"

wait(10)
waitTime = 180
repeat wait(1)waitTime=waitTime-1 Hint.Text=waitTime until waitTime == 0

if waitTime == 0 then

Hint.Text="You (all) have won!"

clean=workspace:GetChildren()
for _,v in pairs(clean)do
if v.className=="Part"then
v:Destroy()

wait(10.50)
Hint.Text="Preparing Next Round.."
end end end end end end end end

1 answer

Log in to vote
2
Answered by
MrFlimsy 345 Moderation Voter
10 years ago

The issue could be the fact that you have a for loop within a for loop, and they both use the variable 'i'. Try changing the second one.

Alternatively, a generic for loop might work better:

for _,v in pairs(player) do
    if v.className=="Player"then
        for _,vv in pairs(newtools) do
            if vv.className=="HopperBin"then
                vv:Clone().Parent=v.Backpack
            end
        end
    end
end
0
Ok, I'll try that. TheeDeathCaster 2368 — 10y
0
Wow, thanks man! It works now! +1 TheeDeathCaster 2368 — 10y
Ad

Answer this question