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

why does the zombie spawner not spawn in the right place?

[ok i found solution]

script.Parent.Transparency = 1 

while wait(math.random(29, 90)) do -- random time to spawn
	z = game.ReplicatedStorage.zombie:Clone()
	local hp = z.Humanoid.MaxHealth
	z:MoveTo(script.Parent.Position) -- move to the spawner's location
	z.Parent = workspace
	z.Humanoid.MaxHealth = math.random(25,100) -- random health
	z.Humanoid.Health = z.Humanoid.MaxHealth
	if hp < 50 then --change skin collor due to health
		z["Left Arm"].Color = Color3.fromRGB(39, 70, 45)
		z["Right Arm"].Color = Color3.fromRGB(39, 70, 45)
		z["Head"].Color = Color3.fromRGB(39, 70, 45)
	else

		z["Left Arm"].Color = Color3.fromRGB(52, 142, 64)
		z["Right Arm"].Color = Color3.fromRGB(52, 142, 64)
		z["Head"].Color = Color3.fromRGB(52, 142, 64)

	end
end

it just ignores line 6 for some reason [ok i found solution]

4 comments

0

I'm pretty sure that the humanoid is what you are supposed to call MoveTo() with

0

So just change line 6 to z.Humanoid:MoveTo(script.Parent.Position)

0

Any errors?

0

No errors but the first time i wrote without z:MoveTo it worked now it doesnt work and the z.humanoid:moveto(script.parent.position) doesnt work

1 answer

2 Things I changed:

  1. Put Waiting at the End and not inside while ... do so it always has a random time

  2. SetPrimaryPartCFrame instead of MoveTo

script.Parent.Transparency = 1 

while true do -- random time to spawn

    z = game.ReplicatedStorage.zombie:Clone()
    local hp = z.Humanoid.MaxHealth
    z:SetPrimaryPartCFrame(script.Parent.Position) -- move to the spawner's location
    z.Parent = workspace
    z.Humanoid.MaxHealth = math.random(25,100) -- random health
    z.Humanoid.Health = z.Humanoid.MaxHealth
    if hp < 50 then --change skin collor due to health
        z["Left Arm"].Color = Color3.fromRGB(39, 70, 45)
        z["Right Arm"].Color = Color3.fromRGB(39, 70, 45)
        z["Head"].Color = Color3.fromRGB(39, 70, 45)
    else

        z["Left Arm"].Color = Color3.fromRGB(52, 142, 64)
        z["Right Arm"].Color = Color3.fromRGB(52, 142, 64)
        z["Head"].Color = Color3.fromRGB(52, 142, 64)

    end
wait(math.random(29, 90)) 
end

1 comment

0

the setprimarycframe made Unable to cast Vector3 to CoordinateFrame error and when i removed '.Position' it makes Unable to cast Instance to CoordinateFrame error

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