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
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