Final Code look like this(LOCAL SCRIPT):
local function WeldTwoParts(A, B)
local weld = Instance.new("WeldConstraint")
weld.Parent = workspace
weld.Part0 = A
weld.Part1 = B
end
local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character
if not Character or not Character.Parent then
Character = Player.CharacterAdded:wait()
end
local HRP = Character.HumanoidRootPart
local Marble = workspace.Marble
wait(5)
character:SetPrimaryPartCFrame(Marble.CFrame)
WeldTwoParts(HRP, Marble)
UserInputService.InputBegan:Connect(functon(input, gameProcessedEvent)
local Camera = workspace.CurrentCamera
local FakeUpVector = Vector3.new(0,1,0)
local RightVector = Camera.CFrame.LookVector:Cross(FakeUpVector)
local LeftVector = -RightVector
local ForwardVector = Camera.CFrame.LookVector
local BackVelocity = -ForwardVector
if input.UserInputType == Enum.UserInputType.Keyboard then
local key = input.KeyCode
if key == Enum.KeyCode.W then
local ForwardVelocity = Instance.new("BodyVelocity", Marble)
ForwardVelocity.Name = "ForwardVelocity"
ForwardVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
ForwardVelocity.Velocity = ForwardVector*250
ForwardVelocity.P = 1000
elseif key == Enum.KeyCode.A then
local LeftVelocity = Instance.new("BoddyVelocity", Marble)
LeftVelocity.Name = "LeftVelocity"
LeftVelocity.P = 10000
LeftVelocity.Velocity = LeftVector*250
elseif key.Enum.KeyCode.D then
local RightVelocity = Instance.new("BoddyVelocity", Marble)
RightVelocity,Name = "RightVelocity"
RightVelocity.P = 10000
RightVelocity.Velocity = RightVector*250
elseif key == Enum.KeyCode.S then
local BackVelocity = Instance.new("BoddyVelocity", Marble)
BackVelocity.Name = "BackVelocity"
BackVelocity.P = 10000
BackVelocity.Velocity = BackVelocity*250
end
end
end)
UserInputService.InputEnded:Connect(function(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.KeyBoard then
local key = input.KeyCode
if key == Enum.KeyCode.W then
if Marble:FindFirstChild("ForwardVelocity") then
Marble.ForwardVelocity:Destroy()
end
end
if key == Enum.KeyCode.A then
if Marble:FindFirstChild("LeftVelocity") then
Marble.LeftVelocity:Destroy()
end
end
if key == Enum.KeyCode.D then
if Marble:FindFirstChild("RightVelocity") then
Marble.RightVelocity:Destroy()
end
end
if key == Enum.KeyCode.S then
if Marble:FindFirstChild("BackVelocity") then
Marble.BackVelocity:Destroy()
end
end
end
end)