#Ore Mining Game Help
46 messages · Page 1 of 1 (latest)
local LoadedBlocks = workspace.LoadedCubes
local OreStorage = game.ServerStorage.Ores
local GeneratedArray = {}
local Layers = {
Florane = {0,0,999},
Crystine = {1,1000,1999},
Hydrolite = {2,2000,2999},
Articine = {3,3000,3999},
Thundrite = {4,4000,4999},
Luxinon = {5,5000,5999},
Shadron = {6,6000,6999},
Ignitine = {7,7000,7999},
Mystile = {8,8000,8999},
Barrier = {9,9000,9000},
STORAGE = {10,9001,9999},
TrueBarrier = {11,10000,10000}
}
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);
}
local function OreSpawnDecider(CubePosition)
local YPosition = CubePosition.Y*-1
local Layer = -1
local LayerName = ""
local ValueName = ""
local ChosenOre
local ChosenOreRarity = 0
for i,CurrentLayer in pairs(Layers) do
if CurrentLayer[2] <= YPosition and CurrentLayer[3] >= YPosition then
Layer = CurrentLayer[1]
LayerName = i
end
end
if Layer == -1 then
return nil
else
if Layer <= 9 then
ValueName = "0"..tostring(Layer)..LayerName
else
ValueName = tostring(Layer)..LayerName
end
end
for _,Ore in pairs(OreStorage:GetChildren()) do
local IsOreBool = Ore:FindFirstChild("IsOre")
if IsOreBool ~= nil then
local RelevantLayerValue = Ore.Values.Layers:FindFirstChild(ValueName)
if IsOreBool.Value and RelevantLayerValue.Value then
local Rarity = Ore.Values.Rarity.Value
local RNGValue = math.random(1,Rarity)
if RNGValue == 1 and Rarity >= ChosenOreRarity then
ChosenOre = Ore
ChosenOreRarity = Rarity
end
end
end
end
return ChosenOre
end
Part one of the script in SServerScriptService.
** You are now Level 2! **
local function Generate(RawPos,CubePos)
local SpawningOre = OreSpawnDecider(CubePos)
if SpawningOre == nil then
return
end
local Ore = SpawningOre:Clone()
Ore.Position = RawPos
Ore.Parent = LoadedBlocks
table.insert(GeneratedArray, string.format("%0.f, %0.f, %0.f", CubePos.X, CubePos.Y, CubePos.Z))
end
_G.OreRemoved = function(pos)
if pos then
for _,pos2 in pairs(Positions) do
local RawNewPos = pos+pos2
local NewPos = Vector3.new((RawNewPos.X)/6,(RawNewPos.Y - 20000)/6,(RawNewPos.Z)/6)
local PreviouslyGenerated = false
for _,Generated in GeneratedArray do
if Generated == string.format("%0.f, %0.f, %0.f", NewPos.X, NewPos.Y, NewPos.Z) then
PreviouslyGenerated = true
end
end
if RawNewPos.Y > 20000 then
PreviouslyGenerated = true
end
if not PreviouslyGenerated then
Generate(RawNewPos,NewPos)
end
end
end
end
local function GenerateMine()
for i = 0,20,1 do
local SpawnCubeX = (i - 10)
for j = 0,20,1 do
local SpawnCubeZ = (j - 10)
local CubePos = Vector3.new(SpawnCubeX,0,SpawnCubeZ)
local RawPos = Vector3.new(SpawnCubeX*6,20000,SpawnCubeZ*6)
Generate(RawPos,CubePos)
end
end
end
GenerateMine()
Second part.
local Tool = script.Parent
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local RunService = game:GetService("RunService")
local LastTarget = nil
local PickaxeEquipped = false
local CurrentlyMining = true
local function PickaxeIsOnYall()
PickaxeEquipped = true
end
local function PickaxeIsOffYall()
PickaxeEquipped = false
end
local function WeMiningYall()
CurrentlyMining = true
end
local function WeNotMiningYall()
CurrentlyMining = false
end
local function AddSelectionBox(Parent)
local SelectionBox = Instance.new("SelectionBox")
SelectionBox.Parent = Parent
SelectionBox.Visible = true
SelectionBox.Color3 = Color3.fromRGB(200,240,255)
SelectionBox.Transparency = 0
SelectionBox.LineThickness = 0.05
SelectionBox.SurfaceTransparency = 1
SelectionBox.Adornee = Parent
end
first part of the localscript inside the tool
local function OreCheckingBaby()
local CurrentTarget = Mouse.Target
if CurrentTarget ~= LastTarget then
if CurrentTarget and PickaxeEquipped then
if CurrentTarget:FindFirstChild("IsOre") then
AddSelectionBox(CurrentTarget)
end
end
if LastTarget then
if LastTarget:FindFirstChild("SelectionBox") then
LastTarget.SelectionBox:Destroy()
end
end
LastTarget = CurrentTarget
else
if LastTarget and not PickaxeEquipped then
if LastTarget:FindFirstChild("SelectionBox") then
LastTarget.SelectionBox:Destroy()
end
end
if CurrentTarget then
if CurrentTarget:FindFirstChild("SelectionBox") == nil and PickaxeEquipped then
AddSelectionBox(CurrentTarget)
end
end
end
if CurrentTarget and PickaxeEquipped then
if CurrentTarget:FindFirstChild("IsOre") and CurrentlyMining then
local Ore = Mouse.Target
_G.OreRemoved(Ore.Position)
Ore:Destroy()
end
end
end
RunService.Heartbeat:Connect(OreCheckingBaby)
Tool.Equipped:Connect(PickaxeIsOnYall)
Tool.Unequipped:Connect(PickaxeIsOffYall)
Mouse.Button1Down:Connect(WeMiningYall)
Mouse.Button1Up:Connect(WeNotMiningYall)
Second part of the LocalScript inside the tool.
Woahhhh
What tutorial is this?
@quaint field copy and paste line 66 of the localscript
Too lazy to count rn
if CurrentTarget and PickaxeEquipped then
if CurrentTarget:FindFirstChild("IsOre") and CurrentlyMining then
local Ore = Mouse.Target
_G.OreRemoved(Ore.Position)
Ore:Destroy()
end
end
end
@charred shoal
_G.OreRemoved = function(pos)
if pos then
for _,pos2 in pairs(Positions) do
local RawNewPos = pos+pos2
local NewPos = Vector3.new((RawNewPos.X)/6,(RawNewPos.Y - 20000)/6,(RawNewPos.Z)/6)
local PreviouslyGenerated = false
for _,Generated in GeneratedArray do
if Generated == string.format("%0.f, %0.f, %0.f", NewPos.X, NewPos.Y, NewPos.Z) then
PreviouslyGenerated = true
end
end
if RawNewPos.Y > 20000 then
PreviouslyGenerated = true
end
if not PreviouslyGenerated then
Generate(RawNewPos,NewPos)
end
end
end
end
this is in the server script service script
Is this a module script?
no
yes
uhhhhhhhh
I kinda just got it from https://devforum.roblox.com/t/global-function/727088/4
Global variables just don’t respect scope. A local variable will no longer exist once you exit the scope, whereas a global will. For example: do local x = 1 y = 2 end print(x, y) --> nil, 2 The same holds true for functions, since they’re just another value that a variable can hold.
asd
Oh nvm
Alr
A default module script
I think this is why
But maybe not idk
I don't really use _G
When you write to _G
It only stays on the side u write it
@quaint field
dang
wait is it possible to use a custom remoteevent to send variables as well
so like if there's like an remote event i would use thatt remote event to trigger the OreRemoved function and then also send the vector3 variable to that function
That's just a normal remit event
U can send values with the remote event as function args
oh lol
i'm kinda new to scripting so i got a bit confused