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

My mining tool only seems to work for 1 ore, yet both have the same code?

Asked by 6 years ago
Edited 6 years ago

I have two ores: Gold Ore and Iron ore. The parts are exactly the same except for the color and the name.

Inside the parts: Script #2 Damage Needed(Value) Damage(Value)

In the picax:

local Damage = 0
------------------------------
local MiningSound = script.Parent.MiningSound
local MinedSound = script.Parent.MinedSound
------------------------------
function reset()
DamageNeeded = 0
Damage = 0  
end
---------------------------------------
script.Parent.Handle.Touched:connect(function(basePart)
    if (basePart.Name == "IronOre") then 
        local player = game.Players:FindFirstChild(script.Parent.Parent.Name)
        local ironore = game.ReplicatedStorage.UnrefinedIronOre:Clone()
        if (player) then
            DamageNeeded = basePart.DamageNeeded.Value
            Damage = Damage+1
            MiningSound:Play()

            if Damage >= DamageNeeded then
                ironore.Parent = player.Backpack
                MinedSound:Play()
                basePart.Name = "CannotMineIronOre"
                basePart.Transparency = 1
                basePart.CanCollide = false
                wait(10)
                reset()
                basePart.Name = "IronOre"
                basePart.Transparency = 0
                basePart.CanCollide = true
            end 
    -----------------------------------------------------------
    if (basePart.Name == "GoldOre") then 
        local player = game.Players:FindFirstChild(script.Parent.Parent.Name)
        local goldore = game.ReplicatedStorage.UnrefinedGoldOre:Clone()
        if (player) then
            DamageNeeded = basePart.DamageNeeded.Value
            Damage = Damage+1
            MiningSound:Play()

            if Damage >= DamageNeeded then
                goldore.Parent = player.Backpack
                MinedSound:Play()
                basePart.Name = "CannotMineGoldOre"
                basePart.Transparency = 1
                basePart.CanCollide = false
                wait(10)
                reset()
                basePart.Name = "GoldOre"
                basePart.Transparency = 0
                basePart.CanCollide = true
            end 
        end
    end
    return (nil);

        end
    end
    end)

In the Gold Ore:
hits = script.Parent.Damage.Value
hitsneeded = script.Parent.DamageNeeded.Value
function onTouch(hit)
    if hit.Parent.Name == "RustyPicax" then
        hits = hits+1
        script.Parent.Mine:Play()
        wait(0.5)
    end
    if hits > hitsneeded then
        script.Parent.CanCollide = false
        script.Parent.Transparency = 1
        print "GoldOreMined"

    end
end

script.Parent.Touched:connect(onTouch)

When the picaxe touches a part, if it is Iron ore or Gold ore it is supposed to increase the hits by 1 until it is >= to the hits needed.

Mining Iron Ore Works fine, Gold doesn't do a thing. Why does Iron work and not gold?

1 answer

Log in to vote
0
Answered by 6 years ago

I don’t think you can define the value of an intvalue in a variable, try taking value out and then adding it to whenever you call the variable. Hope that works for you.

0
It may be that you didn't end the aecond if statement before the gold ore code block started. ThePhantomG 30 — 6y
Ad

Answer this question