I found a tutorial for a decent script to make a monster spawner ,but I do not need it to run upon game start as it was shown in the tutorial. I'm pretty bad at scripting but i tried to have the spawner disabled at start and tried to start it upon enabling but I am jacking something up in the code somewhere and I lack the experience to find out where. If you can help me correct my mistake I would be thankful:)
Script.Target = nil --Entity "character target"
Script.SpawnRate = 5.5 --float "spawn rate"
Script.MaxZombies = 5 --int Max zombs
function Script:Start()
self.enabled = false
end
function Script:Enable()--in
if self.enabled == false then
self.enable = true
self.lastSpawnTime = 0
self.counter = 0
end
end
function Script:UpdatePhysics()
if self.counter >= self.MaxZombies then return end
if Time:GetCurrent() > self.lastSpawnTime + (self.SpawnRate * 1000) then
self.counter = self.counter + 1
self.lastSpawnTime = Time:GetCurrent()
--create a zombie and set location, speed, and target to the player
local zombie = Prefab:Load("AddOns/Zombie Character Pack/zombie1.pfb")
zombie.script:Start()
zombie:SetPosition(self.entity:GetPosition())
zombie.script:Enable()
--zombie.script.Speed = 2
zombie.script.Player = self.Target
end
end