--Made by Luckymaxer


Players = game:GetService("Players")
Debris = game:GetService("Debris")
UserInputService = game:GetService("UserInputService")
ContextActionService = game:GetService("ContextActionService")

Player = Players.LocalPlayer
Character = Player.Character
Mouse = Player:GetMouse()

Humanoid = nil
for i, v in pairs(Character:GetChildren()) do
	if v:IsA("Humanoid") then
		Humanoid = v
		break
	end
end

ServerControl = script:WaitForChild("ServerControl").Value

function InvokeServer(mode, value)
	pcall(function()
		local ServerReturn = ServerControl:InvokeServer(mode, value)
		return ServerReturn
	end)
end

function Dismount()
	if DisableJump then
		DisableJump:disconnect()
	end
	InvokeServer("Dismount")
	if UserInputService.TouchEnabled then
		ContextActionService:UnbindAction("RidableHorse_Dismount")
	end
end

if Humanoid then
	DisableJump = Humanoid.Changed:connect(function(Property)
		if Property == "Jump" then
			Humanoid.Jump = false
			InvokeServer("Jump")
		end
	end)
end

UserInputService.InputBegan:connect(function(InputObject)
	if InputObject.KeyCode == Enum.KeyCode.LeftControl or InputObject.KeyCode == Enum.KeyCode.RightControl then
		Dismount()
	end
end)
