local N=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")local V=game.Players.LocalPlayer local A=V.Character local i=A.Humanoid local t=(script:WaitForChild("\072\111\114\115\101")).Value local G=script:WaitForChild("\072\111\114\115\101\071\117\105")G.Parent=V.PlayerGui i:SetStateEnabled(Enum.HumanoidStateType.Jumping,false)local K=i:LoadAnimation(t.Animations.Ride)K:Play()local o=Vector3.new(0,0,0)N.InputBegan:connect(function(N,V)if not V then if N.KeyCode==Enum.KeyCode.W or N.KeyCode==Enum.KeyCode.Up then o=Vector3.new(o.X,o.Y,-1)elseif N.KeyCode==Enum.KeyCode.S or N.KeyCode==Enum.KeyCode.Down then o=Vector3.new(o.X,o.Y,1)elseif N.KeyCode==Enum.KeyCode.A or N.KeyCode==Enum.KeyCode.Left then o=Vector3.new(-1,o.Y,o.Z)elseif N.KeyCode==Enum.KeyCode.D or N.KeyCode==Enum.KeyCode.Right then o=Vector3.new(1,o.Y,o.Z)elseif N.KeyCode==Enum.KeyCode.Space then local N=Ray.new(t.HumanoidRootPart.Position+Vector3.new(0,-4.3,0),Vector3.new(0,-1,0))local V,A=game.Workspace:FindPartOnRay(N,t)if V and V.CanCollide then t.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)end elseif N.KeyCode==Enum.KeyCode.LeftShift then i:ChangeState(Enum.HumanoidStateType.Jumping)end end end)N.InputEnded:connect(function(N,V)if not V then if N.KeyCode==Enum.KeyCode.W or N.KeyCode==Enum.KeyCode.Up then if o.Z<0 then o=Vector3.new(o.X,o.Y,0)end elseif N.KeyCode==Enum.KeyCode.S or N.KeyCode==Enum.KeyCode.Down then if o.Z>0 then o=Vector3.new(o.X,o.Y,0)end elseif N.KeyCode==Enum.KeyCode.A or N.KeyCode==Enum.KeyCode.Left then if o.X<0 then o=Vector3.new(0,o.Y,o.Z)end elseif N.KeyCode==Enum.KeyCode.D or N.KeyCode==Enum.KeyCode.Right then if o.X>0 then o=Vector3.new(0,o.Y,o.Z)end end end end)spawn(function()while t.Seat.Occupant==i do(game:GetService("\082\117\110\083\101\114\118\105\099\101")).RenderStepped:wait()t.Humanoid:Move(o,true)end G:Destroy()i:SetStateEnabled(Enum.HumanoidStateType.Jumping,true)t.Humanoid:Move(Vector3.new())K: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 horseGui = script:WaitForChild("HorseGui")
horseGui.Parent = player.PlayerGui

humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)

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.Space 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.LeftShift 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)
