Can someone read my script and see what is wrong with it
local FruitToolFolder = RP.FruitTool
local Fruits = RP.Frutis
local RunService = game:GetService("RunService")
local partFolder = game.Workspace.PartHolder
local Cd = 10
local CurrentTime = os.clock()
local itemChances = {}
for i,v in pairs(Fruits:GetChildren()) do
local curChance = v:GetAttribute("Chance")
if curChance == Fruits:GetAttribute("Chance") then
print(v.Name)
itemChances[v.Name] = curChance
end
end
local function GetItem()
local weight = 0
for _, chance in pairs(itemChances) do
weight += chance
end
local randomNum = math.random(1,weight)
weight = 0
for prize, chance in pairs(itemChances) do
weight += chance
if weight >= randomNum then
print("Spawning...", prize)
return prize
end
end
end
local function GetModel(itemName)
for i,v in pairs(Fruits:GetChildren()) do
if v.Name == itemName then
return v
end
end
end
local function GetSpot()
local randomLocation = math.random(1,#partFolder:GetChildren())
return partFolder:GetChildren()[randomLocation]
end
local function SpawnItem()
local itemName = GetItem()
local model = GetModel(itemName)
local spot = GetSpot()
if not model then return end
local modelClone = model:Clone()
modelClone.Parent = workspace.SpawnedItems
modelClone.PrimaryPart.CFrame = spot.CFrame
end
RunService.Heartbeat:Connect(function()
local passedTime = os.clock() - CurrentTime
if passedTime >= Cd then
CurrentTime = os.clock()
print("Spawing Part")
SpawnItem()
end
end)
And why do I get this error