How can I modify this "flying script"?

Good evening, my brother gave me that script he found (thanks to him :smiley:):

local function toggle()
shared.flyEnabled = not shared.flyEnabled
if shared.flyEnabled then
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

local localplayer = plr
local plr = ""

if workspace:FindFirstChild("Core") then
workspace.Core:Destroy()
end

local Core = Instance.new("Part")
Core.Name = "Core"
Core.Size = Vector3.new(0.05, 0.05, 0.05)

spawn(function()
Core.Parent = workspace
local Weld = Instance.new("Weld", Core)
Weld.Part0 = Core
Weld.Part1 = localplayer.Character:FindFirstChild("LowerTorso") or localplayer.Character:FindFirstChild("Torso")
Weld.C0 = CFrame.new(0, 0, 0)
end)

workspace:WaitForChild("Core")

local torso = workspace.Core
flying = true
local speed = 20
local keys = {
a = false,
d = false,
w = false,
s = false
}
local e1
local e2
local function start()
local pos = Instance.new("BodyPosition", torso)
local gyro = Instance.new("BodyGyro", torso)
pos.Name = "EPIXPOS"
pos.maxForce = Vector3.new(math.huge, math.huge, math.huge)
pos.position = torso.Position
gyro.maxTorque = Vector3.new(9e9, 9e9, 9e9)
gyro.cframe = torso.CFrame
repeat
wait()
localplayer.Character.Humanoid.PlatformStand = true
local new = gyro.cframe - gyro.cframe.p + pos.position
if not keys.w and not keys.s and not keys.a and not keys.d then
speed = 20
end
if keys.w then
new = new + workspace.CurrentCamera.CoordinateFrame.lookVector * speed
speed = speed + 0
end
if keys.s then
new = new - workspace.CurrentCamera.CoordinateFrame.lookVector * speed
speed = speed + 0
end
if keys.d then
new = new * CFrame.new(speed, 0, 0)
speed = speed + 0
end
if keys.a then
new = new * CFrame.new(-speed, 0, 0)
speed = speed + 0
end
if speed > 10 then
speed = 20
end
pos.position = new.p
if keys.w then
gyro.cframe = workspace.CurrentCamera.CoordinateFrame * CFrame.Angles(-math.rad(speed * 0), 0, 0)
elseif keys.s then
gyro.cframe = workspace.CurrentCamera.CoordinateFrame * CFrame.Angles(math.rad(speed * 0), 0, 0)
else
gyro.cframe = workspace.CurrentCamera.CoordinateFrame
end
until flying == false
if gyro then
gyro:Destroy()
end
if pos then
pos:Destroy()
end
flying = false
localplayer.Character.Humanoid.PlatformStand = false
speed = 20
end
e1 = mouse.KeyDown:connect(function(key)
if not torso or not torso.Parent then
flying = false
e1:disconnect()
e2:disconnect()
return
end
if key == "w" then
keys.w = true
elseif key == "s" then
keys.s = true
elseif key == "a" then
keys.a = true
elseif key == "d" then
keys.d = true
elseif key == "x" then
if flying == true then
flying = false
else
flying = true
start()
end
end
end)
e2 = mouse.KeyUp:connect(function(key)
if key == "w" then
keys.w = false
elseif key == "s" then
keys.s = false
elseif key == "a" then
keys.a = false
elseif key == "d" then
keys.d = false
end
end)
start()
else
if (game:GetService("Workspace"):FindFirstChild("Core")) then
game:GetService("Workspace"):FindFirstChild("Core"):Destroy()
end
end
end

game:GetService("UserInputService").InputBegan:Connect(function(Input)
if Input.UserInputType == Enum.UserInputType.Keyboard and Input.KeyCode == Enum.KeyCode.X then
toggle()
end
end)

However, it is not entirely what I would like to see. Indeed, my goal is to create a “flying script” to simulate weightlessness for a game about the Soviet lunar rocket (N1) as well as another game about the famous movie “Interstellar.” What I would like is for the script to run without pressing the “X” key. In other words, I would like the script to apply all the time, as soon as the player arrives in the game: without having to press the “X” key. I would also like to reduce the speed of the character’s movement. I tried to change the script for this. (the “speed =” box). I would also like him to know if this one applies to all playersCan you help me change it to achieve my goal?

1) How can I change this script to run without pressing the “X” key?
2) How do I change this script to reduce player speed?
3) Does this script apply to all players?

Thank you in advance,
Baptiste :grinning:

To make the fly script work without pressing the x key, just go from these lines of code:

game:GetService("UserInputService").InputBegan:Connect(function(Input)
if Input.UserInputType == Enum.UserInputType.Keyboard and Input.KeyCode == Enum.KeyCode.X then
toggle()
end
end)

To this:

toggle()

As for the rest, maybe lower the value of the speed variable? I can’t help you with the rest, but I hope you found this useful :slight_smile:

Oh! Thank you so much, it works! For the rest I will manage, thank you very much! :smiley:

1 Like