Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-2

Gold Ore not being able to be mined..?

Asked by 10 years ago

I have gutted a model of Gold Ore from a friend's map that used to be able to be mined with a pickaxe tool. I'm not sure what happened but they completely broke and cease to work.

Help would be greatly appreciated!

Code for ore that is being mined:

local model = script.Parent
local backup = model:clone()
local value = model.Dead

function breakApart()
    local c = model:GetChildren()
    local v = Vector3.new(math.random(-1, 1), 0, math.random(-1, 1))
    for index, child in pairs(c) do
        if child.Name == "Gold" then
            child:remove()
        end
    end
end

function onDied()
    breakApart()
    wait(3)
    backup.Parent = game.Workspace
    backup:MakeJoints()
    model:remove()
end

value.Changed:connect(onDied)

Code for pickaxe tool:

local damage = 1
local money = 15
local reload = 1.5
local tool = script.Parent
local debounce = true

function getDist(pos, pos2)
    return (pos - pos2).magnitude
end

function message(parent, text, time)
    local m = Instance.new("Message")
    m.Text = text
    m.Parent = parent
    wait(time)
    m:remove()
end

function onButton1Down(mouse)
    local target = mouse.Target

    if target == nil then return end

    if debounce == false then return end

    if target.Parent == nil then return end

    if target.Parent.Name ~= "Mine" then return end

    local player = tool.Parent.Parent

    local char = player.Character

    if player == nil then return end

    local dist = getDist(target.Position, char.Head.Position)

    if dist > 3 then return end

    local treehp = target.Parent.HP
    local treedead = target.Parent.Dead

    if treehp == nil or treedead == nil then return end

    if treehp.Value > 0 then

        treehp.Value = treehp.Value - damage

    elseif treehp.Value < 1 and treedead.Value == false then

        treedead.Value = true
        local cash = player.leaderstats.Gold
        cash.Value = cash.Value + money

    end

    if treedead.Value == false then

        debounce = false

        message(player, "Resting, "..(treehp.Value + 1).." hits to go", reload)

        debounce = true

    end
end

function onSelected(mouse)
    print("Equipped")
    mouse.Button1Down:connect(function () onButton1Down(mouse) end)
end

tool.Selected:connect(onSelected)

1 answer

Log in to vote
0
Answered by 10 years ago

I am assuming you have not set these in the gold ore:

    local treehp = target.Parent.HP
    local treedead = target.Parent.Dead

Also I highly suggest you don't use :Remove(); and instead use :Destroy();

0
Thank you for your help. I'm not sure to put the code block though; any pointers? firedum 5 — 10y
Ad

Answer this question