Hello guys, I need help on this Skateboard movement. The Skateboard is welded to the player and it cant be touching the floor, because it has the player orientation. So I thought of setting the player CFrame in a way the Skateboard is touching the surface. The problem is that I don’t know how to do that. I hope someone comes out with any idea…
Here is the entire script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EquipEvent = ReplicatedStorage.Events.VehicleEvents.VehicleEquip
local VehicleMoving = game.ReplicatedStorage.Events.VehicleEvents.VehicleMoving
local VehicleStop = game.ReplicatedStorage.Events.VehicleEvents.VehicleStop
local SmokeParticles = ReplicatedStorage.Particles.WheelParticles:WaitForChild("Smoke Particle")
local FireParticles = ReplicatedStorage.Particles.WheelParticles:WaitForChild("Fire")
local runser = game:GetService("RunService")
local valuetable
local CanSpin = false
EquipEvent.OnServerEvent:Connect(function(player, hover)
local ComponentsFolder = player:WaitForChild("PlayerVehicleComponents")
local Wheel = ReplicatedStorage.Vehicles.Wheels:WaitForChild(ComponentsFolder:WaitForChild("Wheel").Value)
local Body = ReplicatedStorage.Vehicles.Bodies:WaitForChild(ComponentsFolder:WaitForChild("Body").Value):Clone()
Body.Name = "Body"
_G.CurrentBody = Body
local physicalplayer = player.Character or player.CharacterAdded:Wait()
Body.Parent = physicalplayer:WaitForChild("Vehicle")
local WheelPositions = Body:WaitForChild("WheelPositions")
local WheelSize = Body:WaitForChild("WheelSize")
if WheelPositions:FindFirstChild("RearLeftWheelPosition") and WheelPositions:FindFirstChild("RearRightWheelPosition") then
valuetable = {"FrontRight", "FrontLeft", "RearRight", "RearLeft"}
repeat
local Wheelclone = Wheel:Clone()
Wheelclone.Parent = physicalplayer:WaitForChild("Vehicle").Wheels
Wheelclone.Name = valuetable[1].."Wheel"
table.remove(valuetable, 1)
until table.getn(valuetable) == 0
elseif WheelPositions:FindFirstChild("CenterWheelPosition") then
valuetable = {"Right", "Left", "Center"}
repeat
local Wheelclone = Wheel:Clone()
Wheelclone.Parent = physicalplayer:WaitForChild("Vehicle").Wheels
Wheelclone.Name = valuetable[1].."Wheel"
table.remove(valuetable, 1)
until table.getn(valuetable) == 0
else
valuetable = {"Right", "Left"}
repeat
local Wheelclone = Wheel:Clone()
Wheelclone.Parent = physicalplayer:WaitForChild("Vehicle").Wheels
Wheelclone.Name = valuetable[1].."Wheel"
table.remove(valuetable, 1)
until table.getn(valuetable) == 0
end
local hum = physicalplayer:WaitForChild("Humanoid")
_G.Humanoid = hum
hum.HipHeight = Body.HipHeight.Value
local anim = hum:LoadAnimation(Body:FindFirstChildOfClass("Animation"))
anim:Play()
anim.Looped = true
for i, wheel in pairs(physicalplayer.Vehicle.Wheels:GetChildren()) do
local WheelPosition = WheelPositions:FindFirstChild(wheel.Name.."Position")
wheel.CFrame = Body.CFrame + WheelPosition.Value
wheel.Size = WheelSize.Value
local weld = Instance.new("Weld",Body)
weld.Name = wheel.Name.."Weld"
weld.C0 = Body.CFrame:inverse() * wheel.CFrame
weld.Part0 = Body
weld.Part1 = wheel
if wheel.Name == "RearRightWheel" or wheel.Name == "RearLeftWheel" or wheel.Name == "CenterWheel" or wheel.Name == "RightWheel" or wheel.Name == "LeftWheel" then
print(wheel.Name)
local SmokeParticlesclone = SmokeParticles:Clone()
SmokeParticlesclone.Enabled = false
SmokeParticlesclone.Parent = wheel
local FireParticlesclone = FireParticles:Clone()
FireParticlesclone.Enabled = false
FireParticlesclone.Parent = wheel
end
end
physicalplayer.Vehicle.PrimaryPart = Body
physicalplayer.Vehicle:SetPrimaryPartCFrame(physicalplayer.HumanoidRootPart.CFrame)
local weld = Instance.new("Weld",Body)
weld.C0 = physicalplayer.HumanoidRootPart.CFrame:inverse() * physicalplayer.Vehicle.PrimaryPart.CFrame + Body.BodyPosition.Value
weld.Part0 = physicalplayer.HumanoidRootPart
weld.Part1 = Body
end)
VehicleMoving.OnServerEvent:Connect(function(player)
CanSpin = true
local physicalplayer = game.Workspace:WaitForChild(player.Name)
_G.Vehicle = physicalplayer:WaitForChild("Vehicle")
end)
VehicleStop.OnServerEvent:Connect(function()
CanSpin = false
end)
while wait(0.2) do
while CanSpin == true do
local dt = task.wait()
for i, wheel in pairs(_G.Vehicle.Wheels:GetChildren()) do
local Particlesclone = wheel:FindFirstChild("Smoke Particle")
if Particlesclone then
Particlesclone.Enabled = true
end
local weld = _G.CurrentBody:WaitForChild(wheel.Name.."Weld")
weld.C0 = weld.C0 * CFrame.Angles(math.rad(_G.Humanoid.WalkSpeed/-1.5), 0, 0)
end
end
if _G.Vehicle then
for i, wheel in pairs(_G.Vehicle.Wheels:GetChildren()) do
local Particlesclone = wheel:FindFirstChild("Smoke Particle")
if Particlesclone then
Particlesclone.Enabled = false
end
end
end
end