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

Why does this script not decrease/increase? [STILL UNANSWERED]

Asked by 10 years ago

Hello, I have worked on a new script but it seems to be glitchy.

It will always decrease and not increase. Help?

while true do

currentTime = script.Parent.Parent.Current.Value
 wait()
function setName()
    script.Parent.Name = ""..currentTime.." C"
end
    setName()








    if game.Workspace.A.Zig.Value.Value == false then
            wait(5)
        script.Parent.Parent.Current.Value = script.Parent.Parent.Current.Value  +2
    setName()

    else    

    if game.Workspace.A.Zig.Value.Value == true then
            wait(5)
        script.Parent.Parent.Current.Value = script.Parent.Parent.Current.Value  - 2
        setName()


end 
    end
end 

2 answers

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

DrakOMaster did a good job, there's just one problem with his code.

It will keep adding or subtracting until the value is changed to true or false, then set the name. I am assuming you want the name to change every time the value changes. You could do this two different ways. Here is the first way:

local sp = script.Parent
local time = script.Parent.Parent.Current
local zig = game.Workspace.A.Zig.Value

while wait() do

    if zig.Value == false then
        repeat wait(5)
            time.Value = time.Value + 2
        sp.Name = time.." C"
        until zig.Value == true
    end

    if zig.Value == true then
        repeat wait(5)
            time.Value = time.Value - 2
         sp.Name = time.." C"
        until zig.Value == false
    end
end

What this does is edit the name every time the repeat..until loop runs. However, another way to do this would be a .Changed event

local sp = script.Parent
local time = script.Parent.Parent.Current
local zig = game.Workspace.A.Zig.Value

time.Changed:connect(function() --Will fire every time the value of 'time' changes.
    sp.Name = time.." C"
end)

while wait() do

    if zig.Value == false then
        repeat wait(5)
            time.Value = time.Value + 2
        until zig.Value == true
    end

    if zig.Value == true then
        repeat wait(5)
            time.Value = time.Value - 2
        until zig.Value == false
    end
end

Hope i helped!

0
THANKS SO MUCH :) Perfect for my nuclear meltdown >;3 WelpNathan 307 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

You should always have a wait() attached to your while loops - outside of arguments - to prevent crashing.

In the meantime, you may want to invest in some different loops for different situations.

For example:

local sp = script.Parent
local time = script.Parent.Parent.Current
local zig = game.Workspace.A.Zig.Value

while wait() do

    if zig.Value == false then
        repeat wait(5)
            time.Value = time.Value + 2
        until zig.Value == true
    end

    if zig.Value == true then
        repeat wait(5)
            time.Value = time.Value - 2
        until zig.Value == false
    end

    sp.Name = time.." C"

end
0
Thanks for your help, but it still doesn't work :( WelpNathan 307 — 10y
0
Do you have code to change Zig.Value? Drak0Master 172 — 10y
0
No WelpNathan 307 — 10y
0
I am just doing the values manually for now. WelpNathan 307 — 10y

Answer this question