Hi, im making a hover car, and I want to change one value of bodygyro.
Heres the line that is causing it
vehicle.Body.BodyGyro.CFrame = CFrame.new(math.rad(rayFront.Position.Y - rayBack.Position.Y),math.rad(body.BodyGyro.CFrame.Rotation.Y),math.rad(body.BodyGyro.CFrame.Rotation.Z))
Full code – Thank you in advance
local player = game.Players.LocalPlayer
local char = game.Workspace:WaitForChild(player.Name)
local humanoid = char:WaitForChild("Humanoid")
local sitanim = humanoid:LoadAnimation(script.SitAnim)
local driving = false
local UIS = game:GetService("UserInputService")
local tw = game:GetService("TweenService")
humanoid:GetPropertyChangedSignal("Sit"):Connect(function()
if humanoid.Sit == true then
sitanim:Play()
driving = true
local vehicle = humanoid.SeatPart.Parent
local body = vehicle.Body
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = vehicle:GetChildren()
game.ReplicatedStorage.Start:FireServer()
repeat
local ray = workspace:Raycast(body.Position,Vector3.new(0, -100, 0),params)
local rayFront = workspace:Raycast(body.Front.WorldPosition,Vector3.new(0, -100, 0),params)
local rayBack = workspace:Raycast(body.Back.WorldPosition,Vector3.new(0, -100, 0),params)
vehicle.Body.BodyGyro.CFrame = CFrame.new(math.rad(rayFront.Position.Y - rayBack.Position.Y),math.rad(body.BodyGyro.CFrame.Rotation.Y),math.rad(body.BodyGyro.CFrame.Rotation.Z))
if body.Position.Y < rayFront.Position.Y+5 then
body.BodyVelocity.Velocity = Vector3.new(body.BodyVelocity.Velocity.X,1,body.BodyVelocity.Velocity.Z)
else
body.BodyVelocity.Velocity = Vector3.new(body.BodyVelocity.Velocity.X,-1,body.BodyVelocity.Velocity.Z)
end
task.wait()
until driving == false
else
driving = false
sitanim:Stop()
game.ReplicatedStorage.End:FireServer()
end
end)
local a = false
local d = false
local w = false
local s = false
local speed = 0
UIS.InputBegan:Connect(function(key)
if driving == true then
local vehicle = humanoid.SeatPart.Parent
local body = vehicle.Body
local velocity = body.BodyVelocity
if key.KeyCode == Enum.KeyCode.W then
w = true
repeat
if vehicle.Pedal.Orientation.X > -40 then
vehicle.Pedal.Orientation -= Vector3.new(1,0,0)
end
if speed < 100 then
speed += 1
end
velocity.Velocity = body.CFrame.LookVector*speed
task.wait()
until w == false
elseif key.KeyCode == Enum.KeyCode.S then
s = true
repeat
if vehicle.Brake.Orientation.X > -40 then
vehicle.Brake.Orientation -= Vector3.new(1,0,0)
end
if speed > 0 and w == false then
if speed >= 5 then
speed-=2
else
speed = 0
end
end
velocity.Velocity = body.CFrame.LookVector*speed
task.wait()
until s == false
elseif key.KeyCode == Enum.KeyCode.A then
a = true
body.BodyGyro.CFrame *= CFrame.Angles(math.rad(0),math.rad(0),math.rad(0))
vehicle.Wheel.HingeConstraint.TargetAngle = 45
repeat
body.BodyGyro.CFrame *= CFrame.Angles(math.rad(0),math.rad(2),math.rad(0))
task.wait()
until a == false
elseif key.KeyCode == Enum.KeyCode.D then
d = true
vehicle.Wheel.HingeConstraint.TargetAngle = -45
repeat
body.BodyGyro.CFrame *= CFrame.Angles(math.rad(0),math.rad(-2),math.rad(0))
task.wait()
until d == false
end
end
end)
UIS.InputEnded:Connect(function(key)
if driving == true then
local vehicle = humanoid.SeatPart.Parent
local body = vehicle.Body
local velocity = body.BodyVelocity
if key.KeyCode == Enum.KeyCode.W then
w = false
repeat
vehicle.Pedal.Orientation += Vector3.new(2,0,0)
task.wait()
until vehicle.Pedal.Orientation.X >= 0 or w == true
repeat
speed-=1
velocity.Velocity = body.CFrame.LookVector*speed
task.wait(0.1)
until speed == 0 or s == true or w == true
elseif key.KeyCode == Enum.KeyCode.S then
repeat
vehicle.Brake.Orientation += Vector3.new(2,0,0)
task.wait()
until vehicle.Brake.Orientation.X >= 0 or w == true
s = false
elseif key.KeyCode == Enum.KeyCode.A then
body.BodyGyro.CFrame *= CFrame.Angles(math.rad(0),math.rad(0),math.rad(0))
vehicle.Wheel.HingeConstraint.TargetAngle = 0
a = false
elseif key.KeyCode == Enum.KeyCode.D then
vehicle.Wheel.HingeConstraint.TargetAngle = 0
d = false
end
end
end)