Basically I was trying to create a really simple movement script for my horse model. However the horse isn’t moving and there aren’t any errors in the output. What did I do wrong?
This is the source code of the local script I have inside the horse model:
local horse = script.Parent.HRP
local uis = game:GetService("UserInputService")
local bv = Instance.new("BodyVelocity", horse)
local accelerate = false
local speed = 0
bv.Velocity = Vector3.new()
bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
local bg = Instance.new("BodyGyro",horse)
bg.CFrame = CFrame.new()
bg.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
uis.InputBegan:Connect(function(input,istyping)
if horse.Seat.Occupant ~= game.Players.LocalPlayer.Character.Humanoid then return end
if not istyping then
if input.KeyCode == Enum.KeyCode.W then
accelerate = true
repeat
speed = speed + 1
bv.Velocity = horse.CFrame.LookVector * speed
bg.CFrame = horse.CFrame
wait(.5)
until accelerate == false
end
if input.KeyCode == Enum.KeyCode.S then
accelerate = true
if speed > -300 then
repeat
speed = speed - 1
bv.Velocity = horse.CFrame.LookVector * speed
bg.CFrame = horse.CFrame
print(speed)
print(speed < -300)
wait(.5)
until accelerate == false or speed < -300
else
speed = 0
end
end
if input.KeyCode == Enum.KeyCode.A then
bg.CFrame = horse.CFrame * CFrame.Angles(0,math.rad(150),0)
end
if input.KeyCode == Enum.KeyCode.D then
bg.CFrame = horse.CFrame * CFrame.Angles(0,math.rad(-150),0)
end
end
end)
uis.InputEnded:Connect(function(input,istyping)
if horse.Seat.Occupant ~= game.Players.LocalPlayer.Character.Humanoid then return end
if not istyping then
if input.KeyCode == Enum.KeyCode.W then
bg.CFrame = horse.CFrame
accelerate = false
repeat wait()
bv.Velocity = horse.CFrame.LookVector * speed
speed = speed - 1
until
speed == 0 or speed < 0 or accelerate == true
if speed <= 0 and accelerate == false then
speed = 0
bv.Velocity = Vector3.new()
end
end
if input.KeyCode == Enum.KeyCode.S then
bg.CFrame = horse.CFrame
accelerate = false
if speed < 0 then
repeat wait()
bv.Velocity = horse.CFrame.LookVector * speed
speed = speed + 1
until speed > 0 or accelerate == true
if speed > 0 and accelerate == false then
speed = 0
bv.Velocity = Vector3.new()
end
end
end
end
end)