They call it "Beginner Skill"

Hello everyone, I recently got into developing, and I’m not so good at it…
I am making a game where you have a factory that is powered by steam, steam uses water, so i’m trying to make a thing for that so the water slowly decreases, but I’ve got a problem.

There’s a valve that you’d need to click to open it and let the water enter the boiler.
Usually, my developing friend helps me, but he’s on a trip right now, making him unavailable for me.

Here’s the script:

It’s where you click the valve, it would keep on decreasing the water level by 0.001 every time until the valve is clicked again. But here’s the issue: It does not repeat it, and it does not stop when a user clicks(It does not even start in the first place). it’s as if it’s a single click like this:

script.parent.mouseclick:connect(function()
script.parent.parent.parent.Waterlevel1.Value = script.parent.parent.parent.waterlevel1.value + -1 / 100
end)

Anyways, help would be much appreciated :slight_smile:

So I would’ve just did a if else statement instead of that because if else statements can easily be changed

local Click = script.Parent

local Debounce = false

Click.MouseClick:Connect(function()
    Debounce = not Debounce
    if Debounce then
        repeat
           -- Put what you want to repeat here
        until Debounce == false
    else
        -- Change whatever when it ends
    end
end) 

Edit: tested your script too, yours play only once probably because it’s receiving the click signal as well so waiting for a bool to change true/false would work around that issue

1 Like

I’m not sure if i understand this…

I capitalized the I in if by accident so change it into a lower case

oh yeah and dont forget a wait in the repeat

and what is supposed to go in between else and end?

Guessing from looking at your original script you can have the speed go to 0 because putting it after the repeat probably won’t work

Yeah, it doesn’t work. How can i make the speed go back to 0 then?

so I changed the script a bit for you and you’ll need to define the location of the speed yourself but assuming you’re just using angular velocity

local Click = script.Parent
local Speed = --define location of speed

local Debounce = false

Click.MouseClick:Connect(function()
    Debounce = not Debounce
    if Debounce then
        Speed.AngularVelocity = Vector3.new(10,0,0)
        repeat
          script.Parent.Parent.Parent.WaterLevel1.Value += -1 / 1000
        until Debounce == false
    else
        Speed.AngularVelocity = Vector3.new()
    end
end)

or you can disable the velocitys instead of changing the direction

Why did you use a vector3 for the speed? It’s a Hinge Constraint

image

Why is it like this?

@Bubblebuddy200 Nevermind, i just had to define the speed location

It works, after a bit of understanding where to put what :slight_smile: I can’t thank you enough!