I’ve used this script for r15 characters but now I am using it for r6 characters but right now its broken. I tried to replace the PrimaryPart with the Head since it is the PrimaryPart but my character just glitches out the map when I start flying and when I stop flying teleports glitches into the ground. I haven’t found anything useful that would help me edit the script to make it suitable for r6 so any help would be appreciated with tweaking the code or finding a new system.
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local flyButton = script.Parent
local isFlying = false
local currentVelocity = Vector3.new(0, 0, 0)
local currentPosition = character:WaitForChild("PrimaryPart").Position
local function updatePosition()
if isFlying then
currentPosition = currentPosition + currentVelocity
character:SetPrimaryPartCFrame(CFrame.new(currentPosition))
end
end
local function toggleFly()
if not isFlying then
isFlying = true
flyButton.Text = "Stop Flying"
currentVelocity = Vector3.new(0, 50, 0)
else
isFlying = false
flyButton.Text = "Fly"
currentVelocity = Vector3.new(0, 0, 0)
character:SetPrimaryPartCFrame(CFrame.new(Vector3.new(character.PrimaryPart.Position.X, 0, character.PrimaryPart.Position.Z)))
end
end
local function onKeyPress(inputObject, gameProcessedEvent)
if isFlying and not gameProcessedEvent then
local newVelocity = currentVelocity
if inputObject.KeyCode == Enum.KeyCode.W then
newVelocity = newVelocity + Vector3.new(0, 0, -5)
elseif inputObject.KeyCode == Enum.KeyCode.S then
newVelocity = newVelocity + Vector3.new(0, 0, 5)
elseif inputObject.KeyCode == Enum.KeyCode.A then
newVelocity = newVelocity + Vector3.new(-5, 0, 0)
elseif inputObject.KeyCode == Enum.KeyCode.D then
newVelocity = newVelocity + Vector3.new(5, 0, 0)
end
currentVelocity = newVelocity
end
end
flyButton.MouseButton1Click:Connect(toggleFly)
game:GetService("UserInputService").InputBegan:Connect(onKeyPress)
game:GetService("RunService").RenderStepped:Connect(updatePosition)