--- Skill

repeat wait() until game.Players.LocalPlayer.Character

local Player = game.Players.LocalPlayer
local char = Player.Character
local hum = char:WaitForChild("Humanoid")
local Torso = char:WaitForChild("LowerTorso")
local UIS = game:GetService("UserInputService")
local Mouse = Player:GetMouse()
local toggle = false
local Debounce = true
local Speed = 5
local prevdir = Player.Character.HumanoidRootPart.Orientation.Y

local Anim = Instance.new("Animation")
Anim.AnimationId = script.Anim01.AnimationId
local PlayAnim = hum:LoadAnimation(Anim)

local Tween = game:GetService("TweenService")
local Gui = Player.PlayerGui:WaitForChild("Mochi_Skill_List".. Player.Name):WaitForChild("Frame")

local Cooldown = 7



UIS.InputBegan:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.F and Debounce == true and Tool.Equip.Value == true and Tool.Active.Value == "None" then
		
		PlayAnim:Play()
		toggle = true
		Tool.Active.Value = "5RollerDonut"
		script.Fire:FireServer("Start")
		Gui:FindFirstChild(Tool.Active.Value).Frame.Size = UDim2.new(1, 0, 1, 0)
		local BV = Instance.new("BodyVelocity",Torso)
		BV.Name = "BodyVelocityRollDough"
		BV.MaxForce = Vector3.new(math.huge,0,math.huge)
		prevdir = Player.Character.HumanoidRootPart.Orientation.Y
		while script.Parent.Equip.Value == true and toggle == true do
			Player.Character.HumanoidRootPart.CFrame = CFrame.new(Player.Character.HumanoidRootPart.Position, Vector3.new(Mouse.Hit.p.x,Player.Character.HumanoidRootPart.Position.y,Mouse.Hit.p.z))
			BV.Velocity = Player.Character.HumanoidRootPart.CFrame.lookVector * Speed
			if Speed < 80 then
				Speed = Speed + 1.25
			end
			local MaxAngle = 45
			if (Player.Character.HumanoidRootPart.Orientation.Y - prevdir) >= MaxAngle or (Player.Character.HumanoidRootPart.Orientation.Y - prevdir) <= -MaxAngle  then
				Speed = Speed - (Speed/2)
			end
			wait()
			prevdir = Player.Character.HumanoidRootPart.Orientation.Y
		end
	end
end)

UIS.InputEnded:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.F and Debounce == true and Tool.Equip.Value == true and Tool.Active.Value == "5RollerDonut" then
		PlayAnim:Stop()
		Debounce = false
		toggle = false
		script.Fire:FireServer("Release")
		local BV = Torso:FindFirstChild("BodyVelocityRollDough")
		BV.MaxForce = Vector3.new(5000, 0, 5000)
		wait(0.5)
		BV:Destroy()
		Tween:Create(Gui:FindFirstChild(Tool.Active.Value).Frame, TweenInfo.new(Cooldown), {Size = UDim2.new(0, 0, 1, 0)}):Play()
		Tool.Active.Value = "None"
		wait(Cooldown)
		Speed = 5
		Debounce = true
	end
end)
