- What do you want to achieve? Keep it simple and clear!
I want to make a hoverboard movement (driving). I don’t expect full scripts all I need is explanation on how I would do this.
- What is the issue? Include screenshots / videos if possible!
It doesn’t move when I click wasd. All I get is being still.
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried looking at the Roblox jeep but I wasn’t able to make it work.
-- Server Script
local ProximityPromptService = game:GetService("ProximityPromptService")
local Prompt = script.Parent.Parent.ProximityPrompt
local Hoverboard = script.Parent.Parent
-- Values
local currentHumanoid = nil
local currentAnim = nil
local bp = Instance.new("BodyPosition")
bp.D = 1000
bp.MaxForce = Vector3.new(0, 0, 0)
bp.Parent = script.Parent.Parent
local bg = Instance.new("BodyGyro")
bg.MaxTorque = Vector3.new(0, 0, 0)
bg.Parent = script.Parent.Parent
script.Parent.Parent.BackParticles.ParticleEmitter.Enabled = false
script.Parent.Parent.FrontParticles.ParticleEmitter.Enabled = false
Prompt.PromptButtonHoldEnded:Connect(function(player)
local Character = player.Character
local Humanoid = Character.Humanoid
if Humanoid.Health > 0 then
script.Parent.Parent:SetNetworkOwner(player)
Prompt.Enabled = false
currentHumanoid = Humanoid
Humanoid.WalkSpeed = 0
local weld = Instance.new("Weld", script.Parent.Parent)
weld.Name = "PlayerWeld"
weld.Part0 = script.Parent.Parent
weld.Part1 = Character.HumanoidRootPart
weld.C0 = CFrame.new(0, (Character.HumanoidRootPart.Size.Y * 0.5) + Character.Humanoid.HipHeight, 0)
game.ReplicatedStorage.ActivateHoverboard:FireClient(player, script.Parent.Parent)
bp.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bg.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
local Animator = currentHumanoid:FindFirstChild("Animator")
if Animator then
currentAnim = Animator:LoadAnimation(Hoverboard.sitanim)
currentAnim:Play()
end
script.Parent.Parent.BackParticles.ParticleEmitter.Enabled = true
script.Parent.Parent.FrontParticles.ParticleEmitter.Enabled = true
end
end)
-- Client Script
-- Services
local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local HRP = Character.HumanoidRootPart
local ActivateHoverboard = game.ReplicatedStorage:WaitForChild("ActivateHoverboard")
local currentHoverboard = nil
local movement = Vector3.new()
local rotation = 0
local movementSpeed = 10
ActivateHoverboard.OnClientEvent:Connect(function(hb)
print(hb)
currentHoverboard = hb
end)
UIS.InputEnded:Connect(function(input)
if UIS:GetFocusedTextBox() == nil then
print(2)
-- If they want to exit the hoverboard
if input.KeyCode == Enum.KeyCode.F then
currentHoverboard = nil
movement = Vector3.new()
rotation = 0
return
end
-- Movement
if input.KeyCode == Enum.KeyCode.W then
print(1)
movement = Vector2.new(movement.X, 1 * movementSpeed)
elseif input.KeyCode == Enum.KeyCode.A then
print(2)
movement = Vector2.new(-1, movement.Y * movementSpeed)
rotation = 20
elseif input.KeyCode == Enum.KeyCode.S then
print(3)
movement = Vector2.new(movement.X, -1 * movementSpeed)
elseif input.KeyCode == Enum.KeyCode.D then
print(4)
movement = Vector2.new(1, movement.Y * movementSpeed)
rotation = -20
end
end
end)
game:GetService("RunService").Heartbeat:Connect(function()
if currentHoverboard ~= nil then
if movement then
local rayOrigin = currentHoverboard.Position
local rayDirection = -currentHoverboard.CFrame.UpVector * 1000
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {currentHoverboard}
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
if raycastResult then
local groundY = raycastResult.Instance.Position.Y + (raycastResult.Instance.Size.Y / 2)
currentHoverboard.BodyPosition.Position = Vector3.new(currentHoverboard.Position.X, groundY + 1.5, currentHoverboard.Position.Z)
currentHoverboard.BodyGyro.CFrame = currentHoverboard.CFrame * CFrame.Angles(0, rotation, 0)
HRP.Velocity = Vector3.new()
currentHoverboard.PlayerWeld.C0 = CFrame.new(0, (Character.HumanoidRootPart.Size.Y * 0.5) + Character.Humanoid.HipHeight * (groundY + 1), 0)
end
end
end
end)