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

[SOLVED] Invalid argument #1 to 'pairs' (table expected, got Instance) ?

Asked by 1 year ago
Edited 1 year ago

Hey guys need yall help with this i kept getting this error,

Also I'm using a module script, if you can help out i appreciate it.

local ZSModule = {}
function ZSModule.movezombieto(zom, pathtable, pos)
    local wal = zom:WaitForChild("Humanoid"):LoadAnimation(zom:WaitForChild("Config"):WaitForChild("WalkAnim"))
    wal.Priority = Enum.AnimationPriority.Action
    wal:Play()
    spawn(function() zombiehealthcheck(zom) end)

    spawn(function() 
        repeat wait(math.random(5,50)) 
            if zom:WaitForChild("Humanoid").Health > 0 then 
                zom:WaitForChild("Config"):WaitForChild("ZombieRawr"):Play()
                wait(math.random(4, 8))
                zom:WaitForChild("Config"):WaitForChild("ZombieRawr"):Stop()
            end 
        until zom:WaitForChild("Humanoid").Health > 0 
    end)
    for _, pathp in pairs(pathtable) do --Problem
        if zom:WaitForChild("Humanoid").Health > 0 then
            moveTo(zom:WaitForChild("Humanoid"), pathtable.Position)
            zom:WaitForChild("Humanoid").MoveToFinished:Wait()
        end
    end
end

return ZSModule

here's the script's parent or whatever you call it lol (summarised)

local WaveFolder = ServerStorage:WaitForChild("Waves")
local CurrentWave = ReplicatedStorage:WaitForChild("ZombiesFolder"):WaitForChild("CurrentWave")
local pathtable 

zomv = WaveFolder:GetChildren()

        pathtable = workspace:WaitForChild("MapSpawned"):WaitForChild(CurrentMap.Value):WaitForChild("Config"):WaitForChild("Paths")


function NewZombie(ZombieFolder, zomv, pos, parentingto)
    local selectedzombiename = string.split(zomv.Name, " ")
    local selectedzombie = ZombieFolder:WaitForChild(selectedzombiename[2])
    local zomcount = zomv.Value
    for i = 1, zomcount, 1 do
        if CurrentHealth.Value <= 0 then
            break
        end
        wait(1)
        local clonedzom = selectedzombie:Clone()
        for _, characterPart in pairs(clonedzom:GetChildren()) do
            if characterPart:IsA("BasePart") then
                PhysicsService:SetPartCollisionGroup(characterPart, "Players")
            end
        end
        clonedzom.Parent = parentingto
        clonedzom:MoveTo(pos)
        spawn(function()
            ZSModule.movezombieto(clonedzom, pathtable)
        end)
    end
end


function WaveSystem()
    Alarm:Clone().Parent = Arrow
    for _, wav in pairs(WaveFolder:GetChildren()) do
        if string.match(tostring(CurrentWave.Value), wav.Name) then
            print(CurrentWave.Value, wav)
            if CurrentHealth.Value > 0 then
                Arrow:WaitForChild("Alarm"):Play()
                --for count = 1, wav:WaitForChild("ZombiesSpawn").Value, 1 do
                --  print(count)
                --  wait(1)

                --end
                currentwave += 1
                CurrentWave.Value = currentwave

                print(currentwave)
                local currentwavefo = wavetable[currentwave]
                local currentwavefolder = currentwavefo:GetChildren()

                table.sort(currentwavefolder, function(a,b) local aname = string.split(a.Name, " ")[1] local bname = string.split(b.Name, " ")[1] return tonumber(aname)<tonumber(bname) end)



                for _, zoms in pairs(currentwavefolder) do
                    NewZombie(ZombieFolder, zoms, Start.Position, ZombiesSpawnedFolder)
                end


                wait(10)

                CurrentWave.Value = CurrentWave.Value + 1
                RewardPlayersCash = RewardPlayersCash + 50
                for _, plr in pairs(Players:GetPlayers()) do
                    plr:WaitForChild("Leaderstats"):WaitForChild("Cash").Value = plr:WaitForChild("Leaderstats"):WaitForChild("Cash").Value + RewardPlayersCash
                end
            else
                LostZ()
                Arrow:WaitForChild("Alarm"):Destroy()
            end
        end
    end
    if CurrentHealth.Value > 0 then
        TriumphZ()
        Arrow:WaitForChild("Alarm"):Destroy()
    else
        LostZ()
        Arrow:WaitForChild("Alarm"):Destroy()
    end
end
0
Can you show the entire "here's the script's parent or whatever you call it lol" T3_MasterGamer 2189 — 1y
0
I edited, there's actually more but word limit so idk if there's any other way to show XxTechi 0 — 1y
0
or you can add me on discord or smthing XxTechi#4683 XxTechi 0 — 1y
0
change 'pathtable' to workspace:WaitForChild("MapSpawned"):WaitForChild(CurrentMap.Value):WaitForChild("Config"):WaitForChild("Paths"):GetChildren() T3_MasterGamer 2189 — 1y
View all comments (2 more)
0
it's because you forgot :GetChildren() T3_MasterGamer 2189 — 1y
0
It worked! Tysm!! XxTechi 0 — 1y

Answer this question