--[[
	This script handles all behavior for the dinosaur Blue in the Jurassic World Creator Challenge.	
	
	Note:
	With this script detached from the dinosaur-model, we can easily manage more dinosaurs at once! (How cool isn't that..?!)
	This script can also be moved into the Dinosaur if preferred. Just make sure to swap out "workspace:WaitForChild("Blue")" with
	script.Parent or similar. The target path should be the root model currently named "Blue" which contains a model named "Body".
--]]


local ReplicatedStorage = game:GetService("ReplicatedStorage")

local DinosaurModelTemplate = game.Workspace.Blue
DinosaurModelTemplate.Parent = nil
local Dinosaur = require(script.Dinosaur)

local AddToPopperCamIgnore = ReplicatedStorage.AddToPopperCamIgnore

local function spawnDinosaur()
	local DinosaurModel = DinosaurModelTemplate:Clone()
	DinosaurModel.Parent = game.Workspace
	local DinosaurAI = Dinosaur.new(DinosaurModel)
	AddToPopperCamIgnore:FireAllClients(DinosaurModel, true)	
	
	DinosaurModel.Body.Humanoid.Died:Connect(function()
		AddToPopperCamIgnore:FireAllClients(DinosaurModel, false)
		spawnDinosaur()
	end)
end

spawnDinosaur()
