Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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!

1 comment

0

THANKS SO MUCH :) Perfect for my nuclear meltdown >;3

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

4 comments

0

Thanks for your help, but it still doesn't work :(

0

Do you have code to change Zig.Value?

0

No

0

I am just doing the values manually for now.

This discussion is preserved as it was. New answers, comments, and votes are closed.