I’ve been working on a zombie PvE game and when trying to spawn in the zombies, I made this code.
function spawnzombie(zombie)
local z = game.ReplicatedStorage.Zombies:FindFirstChild(zombie):Clone()
z.Parent = workspace
z:MoveTo(script.Parent.Spawn.Position)
end
count = 0
while true do
wait(5)
count = math.random(1,100)
print(count % 2)
if (count % 2) == 0 and not (count % 10) == 0 and not (count % 100) == 0 then
spawnzombie("Heavy")
elseif (count % 5) == 0 and not (count % 10) == 0 then
spawnzombie("Giant")
elseif (count % 10) == 0 and not (count % 100) == 0 then
spawnzombie("Giant Heavy")
elseif (count % 100 == 0) then
spawnzombie("Dankis Zombie")
else
spawnzombie("Zombie")
end
end
Can anyone tell me why when the zombie is actually attempting to be spawned, ROBLOX Studio instantly crashes?
With a quick skim, I’m not entirely sure why your code would cause studio to crash. Are you sure it’s definitely to do with this script? Are there no other possible causes?
p.s Just for future reference, it’s good practice to format your code properly with “```” - three of the weird dash things to the left of the number 1 on the keyboard.
Setting the primarypart cframe should work in his case if he is just spawning the zombie in once. I don’t recommend doing that for animating the zombie; you would use the humanoid:moveto functions.