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

Cant Move Model To Block What's Wrong?

Asked by 9 years ago

Now i know it is probably obvious the answer and all but i can't for the life of me figure it out . . . So, A little help please?

while wait(5) do
    if  script.Parent.NumZom.Value ~= 4 then
        local sp = script.Parent.Parent.Spawn:GetChildren()
        local Zom = Game.ReplicatedStorage.Zombie
        local Num = script.Parent.NumZom
        Num.Value = Num.Value + 1 
        local Zombie = Zom:Clone()
        Zombie.Parent = workspace
        Zombie:MoveTo(math.random(#sp.Position)) 

    end
end

outpost:

02:35:57.306 - Workspace.MAIN.Script:35: attempt to get length of field 'Position' (a nil value) 02:35:57.307 - Stack Begin 02:35:57.307 - Script 'Workspace.MAIN.Script', Line 35 02:35:57.308 - Stack End

Full scrip | | | | | | | | vvvvvvv

 -- Zombie Spawner --
 -- By Coffeemesh  --              -- Credits -- 
                                    -- *UristMcSpark -|- Drooling Zombies (i renamed)
                                    -- *CoffeeMesh -|- Scripting & Black Center Piece
    --          DO NOT EDIT PAST THIS POINT!
--              | | | | | | | | | | | | | | 
--              v v v v v v v v v v v v v v
--___________________________________________________________________________________-- 

Instance.new("IntValue", script.Parent)
script.Parent:WaitForChild("Value")
script.Parent.Value.Name = "NumZom"
--
--
--
--
---
--
--
--
--
--
--
--
--

while wait(5) do
    if  script.Parent.NumZom.Value ~= 4 then
        local sp = script.Parent.Parent.Spawn:GetChildren()
        local Zom = Game.ReplicatedStorage.Zombie
        local Num = script.Parent.NumZom
        Num.Value = Num.Value + 1 
        local Zombie = Zom:Clone()
        Zombie.Parent = workspace
        Zombie:MoveTo(math.random(#sp.Position)) 

    end
end













0
I don't think you can use math.random for MoveTo(), I would try using like a math.random 1-10 or something, and give each value a spawn position, and depending on the number it roles, that's where it spawns. (But I am by no means an expert on math.random() Just giving my thoughts Xoqex 75 — 9y
0
That error is occuring at Line 35, can we see the full script? MasterDaniel 320 — 9y
0
Yes Master ill post it CoffeeMesh 5 — 9y

1 answer

Log in to vote
0
Answered by
Wutras 294 Moderation Voter
9 years ago

You're right. It really is some obvious answer. math.random needs a number as first argument when used for a table. I'll fix the script for you. Also, you wrote sp.Position, but sp is a table, you need to write .Position AFTER the math.random.

 -- Zombie Spawner --
 -- By Coffeemesh  --              -- Credits -- 
                                    -- *UristMcSpark -|- Drooling Zombies (i renamed)
                                    -- *CoffeeMesh -|- Scripting & Black Center Piece
    --          DO NOT EDIT PAST THIS POINT!
--              | | | | | | | | | | | | | | 
--              v v v v v v v v v v v v v v
--___________________________________________________________________________________-- 

Instance.new("IntValue", script.Parent)
script.Parent:WaitForChild("Value")
script.Parent.Value.Name = "NumZom"
--
--
--
--
---
--
--
--
--
--
--
--
--

while wait(5) do
    if  script.Parent.NumZom.Value ~= 4 then
        local sp = script.Parent.Parent.Spawn:GetChildren()
        local Zom = Game.ReplicatedStorage.Zombie
        local Num = script.Parent.NumZom
        Num.Value = Num.Value + 1 
        local Zombie = Zom:Clone()
        Zombie.Parent = workspace
        Zombie:MoveTo(math.random(1, #sp).Position) 

    end
end
0
This didnt work . . . CoffeeMesh 5 — 9y
0
Well, are there even objects inside of the Spawn? Wutras 294 — 9y
Ad

Answer this question