#My gate way system is not working

1 messages · Page 1 of 1 (latest)

tardy holly
#

For some context up, the move of gate is working fine and i will use tween service later
The problem is on the cooldown but i don't know whats wrong, can someone anaylse whats wrong?

local system = button.Parent
local gate = system.Gate.Gate
local cooldown = system.Cooldown

button.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid then
        if cooldown.Value <= 0 then
            cooldown.Value = 60
            local x = gate.Position.X
            local y = 6.689
            local z = gate.Position.Z
            gate.Position = Vector3.new(x,y,z)
            print("succesful!")
        end
    end
    while true do
        if cooldown.Value ~= 0 then
            task.wait(1)
            print(cooldown.Value)
            cooldown.Value = cooldown.Value - 1
        else
            local x = gate.Position.X
            local y = 15
            local z = gate.Position.Z
            gate.Position = Vector3.new(x,y,z)
            break
        end
    end
end)```
tardy holly
#

the cooldown is not taking the second and also going to the negtaive

junior bluff
#

Do you really need the cooldown instance? You can handle it cleanly inside the script without any object instances

#

What u think radish

runic knoll
#

I don't know if this is the fix but try changing the
if cooldown.Value ~= 0 then
to
if cooldown.Value <= 0 then
I don't think it's the fix but right now you're checking if the cooldown is directly 0. And since there can be a floating number(like for example, 0.000000000013 or something) it can mess up a little(Unless you're using an IntValue as the cooldown instead of Numbervalue). Other than that, I don't really know what else

junior bluff
#

It's a conflicting issue, flags like timer running is needed.

junior bluff
#

He prolly went to sleep after posting this.

runic knoll
#

Well if that's the case then I think you can just add debounce?

lapis sinew
#

not 1 second

junior bluff
lapis sinew
#

aka wait 60 seconds

runic knoll
#

Hang on lemme just try and copy all this so I know what went wrong

junior bluff
#

No he's back

#

Let him explain

runic knoll
#

oh ok

tardy holly
junior bluff
#

That ain't the issue

lapis sinew
tardy holly
#

also yeah i could made it inside the script

lapis sinew
#

it so happens that lua while true do if cooldown.Value ~= 0 then task.wait(1) print(cooldown.Value) cooldown.Value = cooldown.Value - 1 else should block all zeros including the first one no matter how many copies of the loop are running

#

but yeah <=0 better practice just in case

lapis sinew
tardy holly
#

k

tardy holly
#

task.wait() is 0 second or near it

lapis sinew
tardy holly
#

yeah

#

i want it to take a second

lapis sinew
tardy holly
#

i plan on added rebirth so its non define

lapis sinew
tardy holly
#

just a placeholder

lapis sinew
runic knoll
#

All you really need is just to add debounce value at the top actually

tardy holly
#

should i put the cooldown to another script?

tardy holly
runic knoll
#

Basically a cooldown, if the debounce is false then set it to true after you pressed on the button and then set it back to false after the cooldown is done, so you can't press on it multiple times until the cooldown is done

south plankBOT
#

studio** You are now Level 3! **studio

tardy holly