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

How to create a working generator?

Asked by 5 years ago

Hi, i'm trying to create a generator with two different modes. On + Maintenance

When the generator is on, it lasts for 60 seconds until going into the state of Maintenance. By that point, a player with the Wrench needs to use it on the generator in order to turn it back on. However, at this point in time; The generator does its count, goes into maintenance, when the tools used, turns back on but the timer doesn't start again. This also doesn't work in live games either... It only works in studio.

Any ideas?

Generator script (server script):

    for i=1,60 do
        wait(1)
        script.Parent.Time.Value = i
        print(i)
    end
    script.Parent.LightA.BrickColor = BrickColor.new("New Yeller")
    script.Parent.LightB.BrickColor = BrickColor.new("New Yeller")
    script.Parent.Status.Value = "Maintenance"
    script.Parent.Time.Value = 0
    wait(1)
    script.Disabled = true

Wrench tool (local script):

tool = script.Parent
tool.Equipped:Connect(function(mouse)
    mouse.Button1Down:Connect(function()
        local t = mouse.Target
        print(t.Parent)
        if t.Parent.Name == "GeneratorA" then
            Repair(t.Parent)
        end
    end)
end)

function Repair(gen)
    gen.LightA.BrickColor = BrickColor.new("Lime green")
    gen.LightB.BrickColor = BrickColor.new("Lime green")
    gen.Status.Value = "On"
    print("repaired")
    gen.Script.Disabled = false
end

Any ideas on how to fix?

Thank you.

Answer this question