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

Cant Move Model To Block What's Wrong?

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













3 comments

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

0

That error is occuring at Line 35, can we see the full script?

0

Yes Master ill post it

1 answer

✓ Accepted answer

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

2 comments

0

This didnt work . . .

0

Well, are there even objects inside of the Spawn?

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