Hey guys, I’m trying to make an ore mining system and I didn’t want each ore to have a script in it so I made a script using collection service and I’m pretty new to it so I don’t know what happened. The error I get is "ServerScriptService.MainOre:12: attempt to index nil with ‘Parent’ " but I’m not sure what to put instead of “Parent”. The tag is correct but I just don’t know what to do with the error. If I could get some help that would be great!
local CollectionService = game:GetService("CollectionService")
for i, ore in pairs(CollectionService:GetTagged("Ore")) do
local health = 50
local bool = true
local ongoing = true
local respawn = math.random(8,20)
local oreName = ore.Name
local ores = game.ReplicatedStorage.Ores:FindFirstChild(oreName)
ore.Touched:Connect(function(ore, hit)
if hit.Parent:FindFirstChild('IsAPick') and ongoing == true then -- error
local status = hit.Parent:FindFirstChild('Type') -- error
if health > 0 then
if status.Value == 'Common' then
health = health - 5
elseif status.Value == 'Uncommon' then
health = health - 10
elseif status.Value == 'Rare' then
health = health - 15
elseif status.Value == 'Epic' then
health = health - 20
end
elseif health <= 0 and bool == true then
bool = false
ore.Transparency = 1
ore.CanCollide = false
local wood = ores:Clone()
wood.Parent = workspace
wood:MoveTo(ore.Position)
ongoing = false
health = 50 -- [ Put the original health here ] --
wait(respawn)
ore.Transparency = 0
ore.CanCollide = true
bool = true
ongoing = true
end
end
end)
end