#Ore Mining Game Help

46 messages · Page 1 of 1 (latest)

quaint field
#

Read the message text.
I get this Error from those scripts:
Players.BloxyColaHugh.Backpack.Default.LocalScript:66: attempt to call a nil value

#
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.

tame plinthBOT
#

studio** You are now Level 2! **studio

quaint field
#
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.

charred shoal
#

What tutorial is this?

#

@quaint field copy and paste line 66 of the localscript

#

Too lazy to count rn

quaint field
#

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

charred shoal
#

Ah alr

#

Probably a typo

#

Show me the OreRemoved func

#

@quaint field

quaint field
# charred shoal Show me the OreRemoved func
_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

charred shoal
quaint field
charred shoal
#

Wait the line 66 shit is a localscript

#

Right?

quaint field
#

yes

charred shoal
#

So how u getting the table

#

From here to there

#

The _G table

quaint field
#

uhhhhhhhh

#
#

asd

charred shoal
#

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

quaint field
#

dang

charred shoal
#

Either define it in local

#

Or use a rem event

#

If it needs to be on server

quaint field
# charred shoal Or use a rem event

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

charred shoal
#

That's just a normal remit event

#

U can send values with the remote event as function args

quaint field
#

oh lol
i'm kinda new to scripting so i got a bit confused