local q=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")local n=game.Players.LocalPlayer local g=n.Character local M=g.Humanoid local N=(script:WaitForChild("\072\111\114\115\101")).Value local d=script.Parent.Parent.Parent local x=false local v=script:WaitForChild("\072\111\114\115\101\071\117\105")v.Parent=n.PlayerGui local P=M:LoadAnimation(N.Animations.Ride)P:Play()local K=Vector3.new(0,0,0)q.InputBegan:connect(function(q,n)if not n then if q.KeyCode==Enum.KeyCode.W or q.KeyCode==Enum.KeyCode.Up then K=Vector3.new(K.X,K.Y,-1)elseif q.KeyCode==Enum.KeyCode.S or q.KeyCode==Enum.KeyCode.Down then K=Vector3.new(K.X,K.Y,1)elseif q.KeyCode==Enum.KeyCode.A or q.KeyCode==Enum.KeyCode.Left then K=Vector3.new(-1,K.Y,K.Z)elseif q.KeyCode==Enum.KeyCode.D or q.KeyCode==Enum.KeyCode.Right then K=Vector3.new(1,K.Y,K.Z)elseif q.KeyCode==Enum.KeyCode.LeftShift then if N.Humanoid.WalkSpeed==45 then N.Humanoid.WalkSpeed=16 else N.Humanoid.WalkSpeed=45 end elseif q.KeyCode==Enum.KeyCode.Q then local q=Ray.new(N.HumanoidRootPart.Position+Vector3.new(0,-4.3,0),Vector3.new(0,-1,0))local n,g=game.Workspace:FindPartOnRay(q,N)if n and n.CanCollide then N.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)end elseif q.KeyCode==Enum.KeyCode.Space then M:ChangeState(Enum.HumanoidStateType.Jumping)end end end)q.InputEnded:connect(function(q,n)if not n then if q.KeyCode==Enum.KeyCode.W or q.KeyCode==Enum.KeyCode.Up then if K.Z<0 then K=Vector3.new(K.X,K.Y,0)end elseif q.KeyCode==Enum.KeyCode.S or q.KeyCode==Enum.KeyCode.Down then if K.Z>0 then K=Vector3.new(K.X,K.Y,0)end elseif q.KeyCode==Enum.KeyCode.A or q.KeyCode==Enum.KeyCode.Left then if K.X<0 then K=Vector3.new(0,K.Y,K.Z)end elseif q.KeyCode==Enum.KeyCode.D or q.KeyCode==Enum.KeyCode.Right then if K.X>0 then K=Vector3.new(0,K.Y,K.Z)end end end end)spawn(function()while N.Seat.Occupant==M do(game:GetService("\082\117\110\083\101\114\118\105\099\101")).RenderStepped:wait()N.Humanoid:Move(K,true)end v:Destroy()M:SetStateEnabled(Enum.HumanoidStateType.Jumping,true)N.Humanoid:Move(Vector3.new())P:Stop()script:Destroy()end)


local userInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character.Humanoid
local horse = script:WaitForChild("Horse").Value
local horsemain = script.Parent.Parent.Parent
local sprinting = false

local horseGui = script:WaitForChild("HorseGui")
horseGui.Parent = player.PlayerGui

local rideAnimation = humanoid:LoadAnimation(horse.Animations.Ride)
rideAnimation:Play()

local movement = Vector3.new(0, 0, 0)

userInputService.InputBegan:connect(function(inputObject, gameProcessedEvent)
	if not gameProcessedEvent then
		if inputObject.KeyCode == Enum.KeyCode.W or inputObject.KeyCode == Enum.KeyCode.Up then
			movement = Vector3.new(movement.X, movement.Y, -1)
		elseif inputObject.KeyCode == Enum.KeyCode.S or inputObject.KeyCode == Enum.KeyCode.Down then
			movement = Vector3.new(movement.X, movement.Y, 1)
		elseif inputObject.KeyCode == Enum.KeyCode.A or inputObject.KeyCode == Enum.KeyCode.Left then
			movement = Vector3.new(-1, movement.Y, movement.Z)
		elseif inputObject.KeyCode == Enum.KeyCode.D or inputObject.KeyCode == Enum.KeyCode.Right then
			movement = Vector3.new(1, movement.Y, movement.Z)
		elseif inputObject.KeyCode == Enum.KeyCode.LeftShift then
			if horse.Humanoid.WalkSpeed == 45 then
				horse.Humanoid.WalkSpeed = 16
			else
				horse.Humanoid.WalkSpeed = 45
			end
			
		elseif inputObject.KeyCode == Enum.KeyCode.Q then
			local ray = Ray.new(horse.HumanoidRootPart.Position + Vector3.new(0, -4.3, 0), Vector3.new(0, -1, 0))
			local hit, position = game.Workspace:FindPartOnRay(ray, horse)
			if hit and hit.CanCollide then
				horse.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
			end
		elseif inputObject.KeyCode == Enum.KeyCode.Space then
			humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
		end
	end
end)

userInputService.InputEnded:connect(function(inputObject, gameProcessedEvent)
	if not gameProcessedEvent then
		if inputObject.KeyCode == Enum.KeyCode.W or inputObject.KeyCode == Enum.KeyCode.Up then
			if movement.Z < 0 then
				movement = Vector3.new(movement.X, movement.Y, 0)
			end
		elseif inputObject.KeyCode == Enum.KeyCode.S or inputObject.KeyCode == Enum.KeyCode.Down then
			if movement.Z > 0 then
				movement = Vector3.new(movement.X, movement.Y, 0)
			end
		elseif inputObject.KeyCode == Enum.KeyCode.A or inputObject.KeyCode == Enum.KeyCode.Left then
			if movement.X < 0 then
				movement = Vector3.new(0, movement.Y, movement.Z)
			end
		elseif inputObject.KeyCode == Enum.KeyCode.D or inputObject.KeyCode == Enum.KeyCode.Right then
			if movement.X > 0 then
				movement = Vector3.new(0, movement.Y, movement.Z)
			end
		end
	end
end)

spawn(function()
	while horse.Seat.Occupant == humanoid do
		game:GetService("RunService").RenderStepped:wait()
		horse.Humanoid:Move(movement, true)
	end
	horseGui:Destroy()
	humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
	horse.Humanoid:Move(Vector3.new())
	rideAnimation:Stop()
	script:Destroy()
end)
