local DBRAutoTrain = Instance.new("ScreenGui")
local Train = Instance.new("Frame")
local Attack = Instance.new("TextButton")
local Defense = Instance.new("TextButton")
local Agility = Instance.new("TextButton")
local Energy = Instance.new("TextButton")
local Charge = Instance.new("TextButton")
local OpenClose = Instance.new("TextButton")
local Name = game.Players.LocalPlayer.Name

DBRAutoTrain.Name = "DBRAutoTrain"
DBRAutoTrain.Parent = game.CoreGui

Train.Name = "Train"
Train.Parent = DBRAutoTrain
Train.BackgroundColor3 = Color3.new(0.631373, 0.631373, 0.631373)
Train.BackgroundTransparency = 0.44999998807907
Train.BorderSizePixel = 0
Train.Position = UDim2.new(0.608576655, 0, 0.657250464, 0)
Train.Visible = false

Attack.Name = "Attack"
Attack.Parent = Train
Attack.BackgroundColor3 = Color3.new(0, 0, 0)
Attack.BackgroundTransparency = 0.30000001192093
Attack.Position = UDim2.new(0.039, 0, 0.077, 0)
Attack.Size = UDim2.new(0, 0, 0, 50)
Attack.Text = "Attack"
Attack.TextColor3 = Color3.new(1, 1, 1)
Attack.TextSize = 0
Attack.TextWrapped = true

Defense.Name = "Defense"
Defense.Parent = Train
Defense.BackgroundColor3 = Color3.new(0, 0, 0)
Defense.BackgroundTransparency = 0.30000001192093
Defense.Position = UDim2.new(0.567, 0, 0.077, 0)
Defense.Size = UDim2.new(0, 0, 0, 50)
Defense.Text = "Defense"
Defense.TextColor3 = Color3.new(1, 1, 1)
Defense.TextSize = 0
Defense.TextWrapped = true

Agility.Name = "Agility"
Agility.Parent = Train
Agility.BackgroundColor3 = Color3.new(0, 0, 0)
Agility.BackgroundTransparency = 0.30000001192093
Agility.Position = UDim2.new(0.039, 0, 0.388, 0)
Agility.Size = UDim2.new(0, 0, 0, 50)
Agility.Text = "Agility"
Agility.TextColor3 = Color3.new(1, 1, 1)
Agility.TextSize = 0
Agility.TextWrapped = true

Energy.Name = "Energy"
Energy.Parent = Train
Energy.BackgroundColor3 = Color3.new(0, 0, 0)
Energy.BackgroundTransparency = 0.30000001192093
Energy.Position = UDim2.new(0.567, 0, 0.385, 0)
Energy.Size = UDim2.new(0, 0, 0, 50)
Energy.Text = "Energy"
Energy.TextColor3 = Color3.new(1, 1, 1)
Energy.TextSize = 0
Energy.TextWrapped = true

Charge.Name = "Charge"
Charge.Parent = Train
Charge.BackgroundColor3 = Color3.new(0, 0, 0)
Charge.BackgroundTransparency = 0.30000001192093
Charge.Position = UDim2.new(0.317, 0, 0.7, 0)
Charge.Size = UDim2.new(0, 0, 0, 50)
Charge.Text = "Charge"
Charge.TextColor3 = Color3.new(1, 1, 1)
Charge.TextSize = 0
Charge.TextWrapped = true

OpenClose.Name = "OpenClose"
OpenClose.Parent = DBRAutoTrain
OpenClose.BackgroundColor3 = Color3.new(0, 0, 0)
OpenClose.Position = UDim2.new(0.86815691, 0, 0.915254235, 0)
OpenClose.Size = UDim2.new(0.118613139, 0, 0.0640301332, 0)
OpenClose.Text = "Open"
OpenClose.TextColor3 = Color3.new(1, 1, 1)
OpenClose.TextScaled = true
OpenClose.TextSize = 14
OpenClose.TextWrapped = true

OpenClose.MouseButton1Click:connect(function()
        if OpenClose.Text == "Close" then
                OpenClose:TweenPosition(UDim2.new(0.868, 0, 0.915, 0), 'Out', 'Linear', 0.2)
                Attack:TweenSize(UDim2.new(0, 0, 0, 50), 'Out', 'Linear', 0.1)
                Defense:TweenSize(UDim2.new(0, 0, 0, 50), 'Out', 'Linear', 0.1)
                Agility:TweenSize(UDim2.new(0, 0, 0, 50), 'Out', 'Linear', 0.1)
                Energy:TweenSize(UDim2.new(0, 0, 0, 50), 'Out', 'Linear', 0.1)
                Charge:TweenSize(UDim2.new(0, 0, 0, 50), 'Out', 'Linear', 0.1)
                Attack.TextScaled = false
                Attack.TextSize = 0
                Defense.TextScaled = false
                Defense.TextSize = 0
                Agility.TextScaled = false
                Agility.TextSize = 0
                Energy.TextScaled = false
                Energy.TextSize = 0     
                Charge.TextScaled = false
                Charge.TextSize = 0
                wait(0.2)
                OpenClose.Text = "Open"
                Train:TweenSizeAndPosition(UDim2.new(0, 0, 0, 0), UDim2.new(0.609, 0, 0.546, 0), 'Out', 'Linear', 0.25)
                wait(0.1)
                Train.Visible = false
        else
                Train.Visible = true
                OpenClose:TweenPosition(UDim2.new(0.737, 0, 0.468, 0), 'Out', 'Linear', 0.2)
                Train:TweenSizeAndPosition(UDim2.new(0.377, 0 , 0.424, 0), UDim2.new(0.609, 0, 0.546, 0), 'Out', 'Linear', 0.25)
                wait(0.2)
                Attack:TweenSize(UDim2.new(0, 166, 0, 50), 'Out', 'Linear', 0.2)
                Defense:TweenSize(UDim2.new(0, 166, 0, 50), 'Out', 'Linear', 0.2)
                Agility:TweenSize(UDim2.new(0, 166, 0, 50), 'Out', 'Linear', 0.2)
                Energy:TweenSize(UDim2.new(0, 166, 0, 50), 'Out', 'Linear', 0.2)
                Charge:TweenSize(UDim2.new(0, 166, 0, 50), 'Out', 'Linear', 0.2)
                OpenClose.Text = "Close"
                wait(0.2)
                Attack.TextScaled = true
                Defense.TextScaled = true
                Agility.TextScaled = true
                Energy.TextScaled = true
                Charge.TextScaled = true
        end
end)

Attack.MouseButton1Click:connect(function()
        if Attack.Text == "Attack" then
                Attack.Text = "Stop Attack AutoTrain"
                while Attack.Text == "Stop Attack AutoTrain" do
                        wait()
                        local remote = game["ReplicatedStorage"]["Remotes"]["Training"]["Combat"]
                        local args = {
                        [1] = {
                        LeftLowerArm = game["Workspace"][Name]["LeftLowerArm"],
                        RightUpperArm = game["Workspace"][Name]["RightUpperArm"],
                        LeftFoot = game["Workspace"][Name]["LeftFoot"],
                        RightHand = game["Workspace"][Name]["RightHand"],
                        RightLowerArm = game["Workspace"][Name]["RightLowerArm"],
                        LeftUpperLeg = game["Workspace"][Name]["LeftUpperLeg"],
                        LeftUpperArm = game["Workspace"][Name]["LeftUpperArm"],
                        Character = game["Workspace"][Name],
                        LeftHand = game["Workspace"][Name]["LeftHand"],
                        RightFoot = game["Workspace"][Name]["RightFoot"],
                        Humanoid = game["Workspace"][Name]["Humanoid"],
                        RightLowerLeg = game["Workspace"][Name]["RightLowerLeg"],
                        RightUpperLeg = game["Workspace"][Name]["RightUpperLeg"],
                        LeftLowerLeg = game["Workspace"][Name]["LeftLowerLeg"]
                        }
                        }
                        remote:InvokeServer(unpack(args))       
                end
        else
                Attack.Text = "Attack"
        end
end)

Defense.MouseButton1Click:connect(function()
        if Defense.Text == "Defense" then
                Defense.Text = "Stop Defense AutoTrain" do
                        while Defense.Text == "Stop Defense AutoTrain" do
                                local remote = game["ReplicatedStorage"]["Remotes"]["Training"]["Defense"]
                                local args = {
                                        [1] = game["Players"][Name]["Stats"],
                                        [2] = game["Players"][Name]["Status"],
                                        [3] = game["Workspace"][Name]["Humanoid"],
                                        [4] = game["Workspace"][Name]["RightHand"]
                                }
                                remote:InvokeServer(unpack(args))
                        end
                end
        else 
                Defense.Text = "Defense"
        end
end)

Agility.MouseButton1Click:connect(function()
        if Agility.Text == "Agility" then
                Agility.Text = "Stop Agility AutoTrain" do
                        while Agility.Text == "Stop Agility AutoTrain" do
                                wait()
                                game.ReplicatedStorage.Remotes.Training.Agility:FireServer(game.Players.Name.Stats)
                        end
                end
        else
                Agility.Text = "Agility"
        end
end)

Energy.MouseButton1Click:connect(function()
        if Energy.Text == "Energy" then
                Energy.Text = "Stop Energy AutoTrain" do
                        while Energy.Text == "Stop Energy AutoTrain" do
                                wait(0.1)
                                local remote = game["ReplicatedStorage"]["Remotes"]["Actions"]["EnergyBlast"]
                                local args = {
                                 [1] = "Left"
                                }
                                remote:InvokeServer(unpack(args))
                        end
                end
        else
                Energy.Text = "Energy"
        end
end)

Charge.MouseButton1Click:connect(function()
        if Charge.Text == "Charge" then 
                Charge.Text = "Stop Charging"
                local remote = Game["ReplicatedStorage"]["Remotes"]["Training"]["Charge"]
                local args = {
                [1] = Game["Players"][Name]["Status"],
                [2] = Game["Workspace"][Name]["UpperTorso"],
                [3] = Game["Workspace"][Name]["Humanoid"]
        }
                remote:InvokeServer(unpack(args))
        else
                local remote = Game["ReplicatedStorage"]["Remotes"]["Training"]["ChargeFinish"]
                local args = {}
                remote:FireServer(unpack(args))
                Charge.Text = "Charge"
        end
end)