error on 55, and attempt to index nil with ':PivotTo' on 57 line
local Plants = require(game.ReplicatedStorage:WaitForChild("Plants"))
local SharedBases = require(game.ServerStorage:WaitForChild("SharedBases"))
local Path = workspace:WaitForChild("Doroga")
local HumMoveTasks = {}
local raritydata = {
{"Common"; 2; Color3.fromRGB(118, 213, 89)},
{"Rare"; 5; Color3.fromRGB(88, 213, 205)},
{"Mythic"; 16; Color3.fromRGB(213, 71, 71)}
}
local function getRandomRarity()
for i, v in ipairs(raritydata) do
local RolledNumber = math.random(1, v[2])
if RolledNumber == 1 and v[2] > raritydata[1][2] then
return {
v[1];
v[2];
v[3];
}
end
end
return raritydata[1]
end
local function moveTo(Humanoid: Humanoid, Target: Vector3, AndThen)
local id = tick()
HumMoveTasks[Humanoid] = id
task.spawn(function()
Humanoid:MoveTo(Target)
Humanoid.MoveToFinished:Wait()
if HumMoveTasks[Humanoid] ~= id then return end
local dist = (Humanoid.RootPart.Position - Target).Magnitude
if dist < 2 then
if AndThen then
AndThen()
end
else
moveTo(Humanoid, Target, AndThen)
end
end)
end
while task.wait(3) do
local randrar = getRandomRarity()
local PlantModels = game:GetService("ReplicatedStorage").Plants[randrar[1]]
local randnum = math.random(1, #PlantModels:GetChildren())
local CNPC: Model = Plants.ClonePlant(PlantModels:GetChildren()[randnum].Name, workspace)
local CHum: Humanoid = CNPC:WaitForChild("Humanoid")
CNPC:PivotTo(workspace.Enter.CFrame)
CHum:MoveTo(workspace.Exit.Position)
moveTo(CHum, workspace.Exit.Position, function()
CNPC:Destroy()
end)
end