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

What's wrong with my script?

I'm trying to get a zombie spawning script but when it spawns, it dies automatically.


waittime = 60 -- 1 min

function StartCountdown()
    waittime = 60 -- Reset the waittime everytime you start a countdown
    for i =1,60 do -- for 1, 60 times do -- This can be done differently, i.e repeat -code- until
    waittime = waittime - 1 -- Minus 1 every second
    wait(1)
end
SpawnZombie() -- Spawn a zombie after the for loop is finished
StartCountdown() -- In Another min another zombie will be spawned
end




function SpawnZombie()
    local Zombie = game.Lighting.Zombie:Clone() -- Assuming its in the lighting and its name is Zombie
    Zombie.Parent = game.Workspace -- You can place the zombie in an appropriate spot and just parent them to workspace when spawning(Easiest way)
    
    for i,v in pairs(Zombie:GetChildren()) do -- This gets the scripts in the zombie and enables them(Keep the scripts in the Zombie Disabled so they dont brake while in the lighting)
        if v:IsA("Script") then 
            v.Disabled = false
        end
    end
end


StartCountdown() -- Run the function to start the game/round

1 answer

✓ Accepted answer

Looks like you didn't get all of your code in a code block, that would help. But I suspect that your zombies may be dying because you aren't calling :MakeJoints() on the zombie to make sure it's all held together.

Add in: Zombie:MakeJoints()

Right after the line where you parent Zombie to Workspace.

8 comments

0

What if it's in lightning? Just do the same thing?

0

Nevermind, going to put it in workspace again

0

Also,what if the script makes it spawn multiple times?

0

Yes, it's fine if you keep the zombie backup Lighting. Just add that line right after the Zombie.Parent = game.Workspace line. Hope this helps!

0

So It's supposed to look like Zombie.Parent = game.Workspace -- You can place the zombie in an appropriate spot and just parent them to workspace when spawning(Easiest way)

0

Linebreak then put Zombie:MakeJoints()?

0

Sorry if this bugs you or not, but How do I move the spawn location up a little? Because It's working and all but It spawns stuck in the ground.

0

As it is, it's not changing the zombie's position at all. It will simply move a copy from lighting to Workspace. To change that position, pu t the zombie in workspace where you want it to spawn, then put it back in lighting. You can do this by cutting, Cntrl+X, and then right clicking lighting and using "Paste into".

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