Hello there,
I have this error in this custom horse my friend gave me, which works in test mode but has an error when I play the game. If anyone knows how to fix this problem, please let me know. Any help is greatly appreciated.
The Error
What the Error does
What it should do
The Script
local player = game.Players.LocalPlayer
local Camera = game.Workspace.CurrentCamera
local mouse = player:GetMouse()
local running = true
local InputService = game:GetService("UserInputService")
local keysDown = {}
InputService.InputBegan:connect(function(input,processed)
if processed then return end
keysDown[input.KeyCode] = true
end)
InputService.InputEnded:connect(function(input,processed)
if processed then return end
keysDown[input.KeyCode] = false
end)
--Where it begins
local UIS = game:GetService("UserInputService")
local Key = Enum.KeyCode.F
UIS.InputBegan:connect(function(Input,GPE)
if not GPE then
if Input.KeyCode == Key then
if player.Character:FindFirstChild("HumanoidRootPart") ~= nil then
local target = mouse.Target
if target and (mouse.Hit.p-player.Character.HumanoidRootPart.Position).magnitude < 10 and mouse.Target.Parent.Name == "BrownHorse" or "WhiteHorse" or "BuckskinHorse" or "GreyHorse" or "BlackHorse" or "ChesnutHorse" then
game.ReplicatedStorage.Events.Mount:InvokeServer(mouse.Target.Parent)
end
end
end
end
end)
----------------------------------------------------------------------------
while wait() do
player.PlayerScripts.ControlScript.Disabled = player.Horse.Value ~= nil
if player.Horse.Value then -- Horse Control
player.Character.Humanoid.AutoRotate = false
local horse = player.Horse.Value
local settings = require(game.ReplicatedStorage.HorseSettings)
local gait = 1
local oldgait = 0
local rotate = 0
local x, y, z = horse.HumanoidRootPart.CFrame:toEulerAnglesXYZ()
if math.abs(z) > 0.1 then
y = -y
else
y = math.pi+y
end
local gaitDebounce = false
local sitAnim = player.Character.Humanoid:LoadAnimation(game.ReplicatedStorage.Animations.HorseSit)
sitAnim:Play()
while player.Horse.Value and player.Horse.Value:FindFirstChild("HumanoidRootPart") do
if gait ~= oldgait then -- Horse animations
oldgait = gait
if gait == 1 then
spawn(function()
game.ReplicatedStorage.Events.Animate:InvokeServer(game.ReplicatedStorage.Animations.HorseBreath,horse)
for i = 0, 2, 1/30 do
wait()
if not player.Horse.Value then return end
end
while wait() and gait == 1 and player.Horse.Value do
local a
local list = {}
for i, k in ipairs(settings.IdleAnimations) do
for j = 1, k.Weight do
list[i+j-1] = k
end
end
local a = list[math.random(1,#list)]
game.ReplicatedStorage.Events.Animate:InvokeServer(a.Anim,horse)
for i = 0, a.Length, 1/30 do
wait()
if not player.Horse.Value then return end
end
end
end)
else
local a = settings.Gaits[gait].Animation
game.ReplicatedStorage.Events.Animate:InvokeServer(a,horse)
end
end
local speed = settings.Gaits[gait].Speed
if keysDown[Enum.KeyCode.A] then
rotate = math.min(rotate + 6/speed,60/speed)
elseif keysDown[Enum.KeyCode.D] then
rotate = math.max(rotate - 6/speed,-60/speed)
elseif rotate ~= 0 then
if math.abs(rotate) < 0.2 then
rotate = 0
else
rotate = (math.abs(rotate) - 6/speed) * rotate/math.abs(rotate)
end
end
if keysDown[Enum.KeyCode.W] and not gaitDebounce then
gait = math.min(gait + 1,#settings.Gaits)
gaitDebounce = true
spawn(function()
wait(0.3)
repeat wait() until not keysDown[Enum.KeyCode.W]
gaitDebounce = false
end)
end
if keysDown[Enum.KeyCode.S] and not gaitDebounce then
gait = math.max(gait - 1,1)
gaitDebounce = true
spawn(function()
wait(0.8)
repeat wait() until not keysDown[Enum.KeyCode.S]
gaitDebounce = false
end)
end
if speed < 1 then
rotate = 0
end
y = y + math.rad(rotate)
speed = (settings.Gaits[gait].Speed*15) / (15+math.abs(rotate))
if gait >= 3 then
speed = speed * horse.Speed.Value
end
speed = (speed + horse.HumanoidRootPart.BodyVelocity.Velocity.magnitude*9)/10
local dir =(CFrame.Angles(0,y,0)*CFrame.new(0,0,1)).p
horse.HumanoidRootPart.BodyVelocity.Velocity = dir * speed
horse.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(),dir) + horse.HumanoidRootPart.Position
wait()
end
sitAnim:Stop()
player.Character.Humanoid.AutoRotate = true
end
end