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

Tycoon furnace not working properly all ores getting destroyed how to fix?

Asked by 4 years ago
Edited 4 years ago

So i have a furnace for my tycoon -- it works in the sense that it destroys the ores and adds money however the issue comes when i attempt to use 2 different 'droppers'

(just a side note i have 2 droppers, 1 drops an ore Named ore1 and the other ore2

if ore2 goes into the furnace before ore1 ore1 is 'processed' by the furnace and gets destroyed and gives the player money - i would like them to both separately go into the furnace excuse the messy code : P

Furnace Code

function onTouch(hit)

        if hit.Parent:FindFirstChild("ore1") then
        local Part1 = game.Workspace:FindFirstChild("ore1")
        local ore1Value = 25
            Part1:Destroy()

            game.Workspace["Tycoon 1"].DropperMoney.Value = game.Workspace["Tycoon 1"].DropperMoney.Value + ore1Value

                else
        if hit.Parent:FindFirstChild("ore2") then
        local Part2 = game.Workspace:FindFirstChild("ore2")
        local ore2Value = 50
            Part2:Destroy()

            game.Workspace["Tycoon 1"].DropperMoney.Value = game.Workspace["Tycoon 1"].DropperMoney.Value + ore2Value


        end
    end
end



script.Parent.Touched:Connect(onTouch)

if there is any code you need me to add please tell me (:

0
Aren't they supposed to be destroyed? Isn't that the point of a furnace in a dropper tycoon? DeceptiveCaster 3761 — 4y
0
hmm lemme try n' explain so ore1 is at the start of the conveyor and ore2 is at the furnace, when ore2 is destroyed the same happens to ore1 while it's at the start of the conveyor rocks5110 7 — 4y
0
Ah. You can change the names of the ores if they both have the same name. DeceptiveCaster 3761 — 4y
0
i have 2 droppers 1 drops an ore Named ore1 and the other ore2 rocks5110 7 — 4y
View all comments (2 more)
0
doesn't it need to be "elseif"? not else and then if srimmbow 241 — 4y
0
the 1st ore still dies rocks5110 7 — 4y

1 answer

Log in to vote
0
Answered by
OBenjOne 190
4 years ago

I think I see what is happening. So ore2 hits the furnace, and you create a variable "hit" that represents that part. Then on line 3 you get "hit.parent". I am assuming your ore is a child of workspace so hit.parent is the workspace. Because ore1 is at the back of the conveyer and a child of workspace, line 3 detects ore1 and destroys it, then promptly detects ore2 as well getting rid of both of them. To fix this, use

 if hit.Name == ("Ore1")

Instead of

 if hit.Parent:FindFirstChild("Ore1")
0
You should also fix line 11 so that all Ore2 parts are not destroyed OBenjOne 190 — 4y
0
Thanks (: rocks5110 7 — 4y
Ad

Answer this question