local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local player = game.Players.LocalPlayer
local function createBall(character)
for _, part in pairs(character:GetChildren()) do
if part:IsA("BasePart") then part:Destroy() end
end
local ball =
Instance.new ("Part")
ball.Shape = Enum.PartType.Ball
ball.Size =
Vector3.new (4, 4, 4)
ball.Position = character.PrimaryPart.Position
ball.Anchored = false
ball.CanCollide = true
ball.Parent = workspace
local bodyVelocity =
Instance.new ("BodyVelocity")
bodyVelocity.MaxForce =
Vector3.new (10000, 10000, 10000)
bodyVelocity.Velocity =
Vector3.new (0, 0, 0)
bodyVelocity.Parent = ball
character.PrimaryPart = ball
local movementDirection =
Vector3.new (0, 0, 0)
local function onInput(input, gameProcessedEvent)
if gameProcessedEvent then return end
if input.KeyCode == Enum.KeyCode.W then movementDirection =
Vector3.new (0, 0, -1) end
if input.KeyCode == Enum.KeyCode.S then movementDirection =
Vector3.new (0, 0, 1) end
if input.KeyCode == Enum.KeyCode.A then movementDirection =
Vector3.new (-1, 0, 0) end
if input.KeyCode == Enum.KeyCode.D then movementDirection =
Vector3.new (1, 0, 0) end
end
UserInputService.InputBegan:Connect(onInput)
RunService.Heartbeat:Connect(function() bodyVelocity.Velocity = movementDirection * 50 end)
end
player.CharacterAdded:Connect(createBall)