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

[Solved]Script Not Incrementing Correctly?

Asked by
Donut792 216 Moderation Voter
4 years ago
Edited 4 years ago

alright so in this script its pretty simple a value is created and set to 1 and if it is 1 then increase it by 1 and if it is equal to 5 then decrease it by 1 but for some ungodly reason life just isnt simple like that and the next button instantly sets it to 5 and the previous button instantly sets it to 1

LocalScript:

local NextButton = script.Parent.Next
local PreviousButton = script.Parent.Previous
local WhiteHex = script.Parent.White.Value
local TanHex = script.Parent.Tan.Value
local LatinoHex = script.Parent.Latino.Value
local LightskinHex = script.Parent.Lightskin.Value
local BrownHex = script.Parent.Brown.Value
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Value = 1

NextButton.MouseButton1Click:Connect(function()
    if Value == 1 then
        Value = Value + 1
        for i,v in pairs(Character:GetChildren()) do
            if v:IsA("BodyColors") then
                v.HeadColor3 = WhiteHex
                v.LeftArmColor3 = WhiteHex
                v.LeftLegColor3 = WhiteHex
                v.RightArmColor3 = WhiteHex
                v.RightLegColor3 = WhiteHex
                v.TorsoColor3 = WhiteHex
            end
        end
    end
    if Value == 2 then
        Value = Value + 1
        for i,v in pairs(Character:GetChildren()) do
            if v:IsA("BodyColors") then
                v.HeadColor3 = TanHex
                v.LeftArmColor3 = TanHex
                v.LeftLegColor3 = TanHex
                v.RightArmColor3 = TanHex
                v.RightLegColor3 = TanHex
                v.TorsoColor3 = TanHex
            end
        end
    end
    if Value == 3 then
        Value = Value + 1
        for i,v in pairs(Character:GetChildren()) do
            if v:IsA("BodyColors") then
                v.HeadColor3 = LatinoHex
                v.LeftArmColor3 = LatinoHex
                v.LeftLegColor3 = LatinoHex
                v.RightArmColor3 = LatinoHex
                v.RightLegColor3 = LatinoHex
                v.TorsoColor3 = LatinoHex
            end
        end
    end
    if Value == 4 then
        Value = Value + 1
        for i,v in pairs(Character:GetChildren()) do
            if v:IsA("BodyColors") then
                v.HeadColor3 = LightskinHex
                v.LeftArmColor3 = LightskinHex
                v.LeftLegColor3 = LightskinHex
                v.RightArmColor3 = LightskinHex
                v.RightLegColor3 = LightskinHex
                v.TorsoColor3 = LightskinHex
            end
        end
    end
    if Value == 5 then
        for i,v in pairs(Character:GetChildren()) do
            if v:IsA("BodyColors") then
                v.HeadColor3 = BrownHex
                v.LeftArmColor3 = BrownHex
                v.LeftLegColor3 = BrownHex
                v.RightArmColor3 = BrownHex
                v.RightLegColor3 = BrownHex
                v.TorsoColor3 = BrownHex
            end
        end
    end
print(Value)
end)

PreviousButton.MouseButton1Click:Connect(function()
    if Value == 5 then
        Value = Value - 1
        for i,v in pairs(Character:GetChildren()) do
            if v:IsA("BodyColors") then
                v.HeadColor3 = BrownHex
                v.LeftArmColor3 = BrownHex
                v.LeftLegColor3 = BrownHex
                v.RightArmColor3 = BrownHex
                v.RightLegColor3 = BrownHex
                v.TorsoColor3 = BrownHex
            end
        end
    end
    if Value == 4 then
        Value = Value - 1
        for i,v in pairs(Character:GetChildren()) do
            if v:IsA("BodyColors") then
                v.HeadColor3 = LightskinHex
                v.LeftArmColor3 = LightskinHex
                v.LeftLegColor3 = LightskinHex
                v.RightArmColor3 = LightskinHex
                v.RightLegColor3 = LightskinHex
                v.TorsoColor3 = LightskinHex
            end
        end
    end
    if Value == 3 then
        Value = Value - 1
        for i,v in pairs(Character:GetChildren()) do
            if v:IsA("BodyColors") then
                v.HeadColor3 = LatinoHex
                v.LeftArmColor3 = LatinoHex
                v.LeftLegColor3 = LatinoHex
                v.RightArmColor3 = LatinoHex
                v.RightLegColor3 = LatinoHex
                v.TorsoColor3 = LatinoHex
            end
        end
    end
    if Value == 2 then
        Value = Value - 1
        for i,v in pairs(Character:GetChildren()) do
            if v:IsA("BodyColors") then
                v.HeadColor3 = TanHex
                v.LeftArmColor3 = TanHex
                v.LeftLegColor3 = TanHex
                v.RightArmColor3 = TanHex
                v.RightLegColor3 = TanHex
                v.TorsoColor3 = TanHex
            end
        end
    end
    if Value == 1 then
        for i,v in pairs(Character:GetChildren()) do
            if v:IsA("BodyColors") then
                v.HeadColor3 = WhiteHex
                v.LeftArmColor3 = WhiteHex
                v.LeftLegColor3 = WhiteHex
                v.RightArmColor3 = WhiteHex
                v.RightLegColor3 = WhiteHex
                v.TorsoColor3 = WhiteHex
            end
        end
    end
print(Value)
end)

Solved the issue with elseif's

Answer this question