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
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!
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