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

How do I create back and forward loop?

Asked by
noammao 294 Moderation Voter
6 years ago

So I am trying to create a character customisation but I am not sure how to create a proper script for that. I mean a module script would work I guess but I think its easier to use global functions. I created a script that increases its global function value by 1 everytime it loops but I get this weird bug that makes it increase by one and then go down. Hard to explain let me show you:

So this one makes it loop forward

local table = {"Bright blue","Magenta","Maroon","Pastel orange","Lapis","Camo","Neon orange","Pastel green","Dark stone grey","Really black"}
_G.snr = 1

script.Parent.Parent.Parent.ShirtValue.Value = "Bright blue"




script.Parent.MouseButton1Down:connect(function()
    script.Parent.Parent.Parent.ShirtValue.Value = table[1 + _G.snr]
    wait()
    script.Parent.Parent.Parent.ShirtColor.Text = (table[1 + _G.snr])
    if _G.snr == 9 then
                _G.snr = 0


        else
    _G.snr = _G.snr + 1
    end
end)

and this one makes it loop backwards.

local table = {"Bright blue","Magenta","Maroon","Pastel orange","Lapis","Camo","Neon orange","Pastel green","Dark stone grey","Really black"}







script.Parent.MouseButton1Down:connect(function()
    script.Parent.Parent.Parent.ShirtValue.Value = table[1 + _G.snr]
    wait()
    script.Parent.Parent.Parent.ShirtColor.Text = (table[1 + _G.snr])
    if _G.snr == 1 then
                _G.snr = 9


        else
    _G.snr = _G.snr - 1
    end
end)

The tree for this is: game.Startergui.screengui.frame.parts(folder).leftShirt(textbutton).localscript and game.Startergui.screengui.frame.parts(folder).rightShirt(textbutton).localscript

also to clarify I am trying to make this: [(https://imgur.com/BsP3cK2)]

Answer this question