im trying to make it so when the player mines a block, there is a chance itll spawn something rare (think like rex:r or untitled mining game, if you havent played those then go play them to see what im referring to if you dont know)
the problem im having is i cant actually pull the rarity and the actual block itself at the same time, the original script i found from a tutorial (cause im making this game for fun and i dont wanna put too much time in it) only allows for one single block to be generated.
i have looked through multiple devforum posts and youtube videos, ive tried mixing two scripts together but im not the greatest at scripting especially when it comes to mixing two scripts together, so im struggling to make it actually work
this is the main script i have
local loottable = require(game.ServerStorage:WaitForChild("LootTable"))
print(loottable)
local ores = game.ServerStorage.Ores
local positions = {
Vector3.new(6,0,0);
Vector3.new(-6,0,0);
Vector3.new(0,6,0);
Vector3.new(0,-6,0);
Vector3.new(0,0,6);
Vector3.new(0,0,-6);
}
function Generate(pos)
if pos then
for _,pos2 in pairs(positions) do
local newPos = pos+pos2
local previouslyGenerated
for _,generated in pairs(workspace.Cubes.Generated:GetChildren()) do
if generated.Value == newPos then
previouslyGenerated = true
end
end
if newPos.Y > 0 then
previouslyGenerated = true
end
if not previouslyGenerated then
function GetRandomOre()
local Sum=0
for OreName,Chance in pairs(loottable) do
Sum += Chance
end
local RandomNumber = math.random(Sum)
for OreName,Chance in pairs(loottable) do
if RandomNumber <= Chance then
return OreName
else
RandomNumber -= Chance
end
end
end
local orerarity = loottable
local ore = game.ServerStorage.Ores.banana:Clone()
ore.Position = newPos
ore.Parent = workspace.Cubes
ore.ClickDetector.MouseClick:Connect(function()
Generate(ore.Position)
ore:Destroy()
end)
local val = Instance.new("Vector3Value")
val.Value = newPos
val.Parent = workspace.Cubes.Generated
end
end
end
end
for i,cube in pairs(workspace.Cubes:GetChildren()) do
if cube:IsA("Part") then
local val = Instance.new("Vector3Value")
val.Value = cube.Position
val.Parent = workspace.Cubes.Generated
cube.ClickDetector.MouseClick:Connect(function()
Generate(cube.Position)
cube:Destroy()
end)
end
end
this is my loottable
module.OreRarities {
["grass"] = 1,
["banana"] = 99,
}
module.Ores {
["grass"] = {
game.ServerStorage.Ores.grass
},
["banana"] = {
game.ServerStorage.Ores.banana
},
}