0% found this document useful (0 votes)
22 views9 pages

Thing

The document is a Lua script for a Roblox game that implements flight mechanics and NPC creation. It includes GUI elements for user interaction, allowing players to launch themselves and fly using specific key inputs. Additionally, it features NPC creation with random cosmetics and movement behavior, enhancing the gameplay experience.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views9 pages

Thing

The document is a Lua script for a Roblox game that implements flight mechanics and NPC creation. It includes GUI elements for user interaction, allowing players to launch themselves and fly using specific key inputs. Additionally, it features NPC creation with random cosmetics and movement behavior, enhancing the gameplay experience.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

-- Services

local Players = game:GetService("Players")


local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")

local player = [Link]

-- Character
local function getCharacter()
■local character = [Link] or [Link]:Wait()
■local humanoid = character:WaitForChild("Humanoid")
■local root = character:WaitForChild("HumanoidRootPart")
■return character, humanoid, root
end

-- ================= GUI =================


local gui = [Link]("ScreenGui")
[Link] = "FlightGui"
[Link] = false
[Link] = player:WaitForChild("PlayerGui")

local function createLabel(text, y)


■local frame = [Link]("Frame")
■[Link] = [Link](260, 70)
■[Link] = [Link](0.5, y)
■[Link] = [Link](0.5, 0.5)
■frame.BackgroundColor3 = [Link](30, 30, 30)
■[Link] = 0
■[Link] = gui

■local corner = [Link]("UICorner")


■[Link] = [Link](0, 12)
■[Link] = frame

■local label = [Link]("TextLabel")


■[Link] = [Link](1, 1)
■[Link] = 1
■[Link] = text
■label.TextColor3 = [Link](255, 255, 255)
■[Link] = true
■[Link] = [Link]
■[Link] = frame
end

createLabel("Press F to get launched", 0.65)


createLabel("Press R to fly", 0.75)

-- Popup
local popup = [Link]("TextLabel")
[Link] = [Link](320, 80)
[Link] = [Link](0.5, 0.4)
[Link] = [Link](0.5, 0.5)
popup.BackgroundColor3 = [Link](20, 20, 20)
[Link] = "Thank you for flying"
popup.TextColor3 = [Link](255, 255, 255)
[Link] = true
[Link] = [Link]
[Link] = false
[Link] = gui

local popupCorner = [Link]("UICorner")


[Link] = [Link](0, 14)
[Link] = popup

-- ================= FLING (F) =================


local function fling()
■local _, humanoid, root = getCharacter()
■[Link] = true

■[Link] = [Link](
■■[Link](-120, 120),
■■[Link](80, 140),
■■[Link](-120, 120)
■)

■[Link] = [Link](
■■[Link]([Link](0, 360)),
■■[Link]([Link](0, 360)),
■■[Link]([Link](0, 360))
■)
end

-- ================= INFINITE FLIGHT =================


local flying = false
local linearVelocity
local alignOrientation
local attachment
local flySpeed = 90
local popupShown = false

local function startFlight()


■if flying then return end
■flying = true

■local _, humanoid, root = getCharacter()


■[Link] = false
■humanoid:ChangeState([Link])

■attachment = [Link]("Attachment")
■[Link] = root

■linearVelocity = [Link]("LinearVelocity")
■linearVelocity.Attachment0 = attachment
■[Link] = [Link]
■[Link] = [Link]
■[Link] = root

■alignOrientation = [Link]("AlignOrientation")
■alignOrientation.Attachment0 = attachment
■[Link] = [Link]
■[Link] = 200
■[Link] = root

■if not popupShown then


■■popupShown = true
■■[Link] = true
■■[Link] = 0
■■[Link] = 0

■■TweenService:Create(
■■■popup,
■■■[Link](2),
■■■{
■■■■BackgroundTransparency = 1,
■■■■TextTransparency = 1
■■■}
■■):Play()

■■[Link](2, function()
■■■[Link] = false
■■end)
■end
end

local function stopFlight()


■if not flying then return end
■flying = false

■local _, humanoid, _ = getCharacter()


■[Link] = true
■humanoid:ChangeState([Link])

■if linearVelocity then linearVelocity:Destroy() end


■if alignOrientation then alignOrientation:Destroy() end
■if attachment then attachment:Destroy() end
end

-- Continuous movement (NO decay)


[Link]:Connect(function()
■if not flying then return end

■local _, _, root = getCharacter()


■local cam = [Link]

■local move = [Link](0, 0, 0)

■if UserInputService:IsKeyDown([Link].W) then


■■move = move + [Link]
■end
■if UserInputService:IsKeyDown([Link].S) then
■■move = move - [Link]
■end
■if UserInputService:IsKeyDown([Link].A) then
■■move = move - [Link]
■end
■if UserInputService:IsKeyDown([Link].D) then
■■move = move + [Link]
■end
■if UserInputService:IsKeyDown([Link]) then
■■move = move + [Link](0, 1, 0)
■end
■if UserInputService:IsKeyDown([Link]) then
■■move = move - [Link](0, 1, 0)
■end

■if [Link] > 0 then


■■move = [Link] * flySpeed
■end

■[Link] = move
■[Link] =
■■[Link]([Link], [Link] + [Link])
end)

-- ================= INPUT =================


[Link]:Connect(function(input, gpe)
■if gpe then return end

■if [Link] == [Link].F then


■■fling()
■elseif [Link] == [Link].R then
■■if flying then
■■■stopFlight()
■■else
■■■startFlight()
■■end
■end
end)
-------------------------------------------------
-- SERVICES
-------------------------------------------------
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local Workspace = game:GetService("Workspace")

-------------------------------------------------
-- PLAYER
-------------------------------------------------
local player = [Link]
local character = [Link] or [Link]:Wait()

-------------------------------------------------
-- UI
-------------------------------------------------
local gui = [Link]("ScreenGui")
[Link] = false
[Link] = [Link]
local frame = [Link]("Frame")
[Link] = [Link](0.32, 0, 0.15, 0)
[Link] = [Link](0.34, 0, 0.4, 0)
frame.BackgroundColor3 = [Link](20, 20, 20)
[Link] = 0
[Link] = true
[Link] = gui

local label = [Link]("TextLabel")


[Link] = [Link](1, 0, 1, 0)
[Link] = 1
[Link] = "PRESS G TO SURPRISE"
[Link] = [Link]
[Link] = 20
label.TextColor3 = [Link](200, 255, 255)
[Link] = frame

-------------------------------------------------
-- UI DRAG
-------------------------------------------------
local dragging = false
local dragStart, startPos

[Link]:Connect(function(input)
■if [Link] == [Link].MouseButton1 then
■■dragging = true
■■dragStart = [Link]
■■startPos = [Link]

■■[Link]:Connect(function()
■■■if [Link] == [Link] then
■■■■dragging = false
■■■end
■■end)
■end
end)

[Link]:Connect(function(input)
■if [Link] == [Link] and dragging then
■■local delta = [Link] - dragStart
■■[Link] = [Link](
■■■[Link],
■■■[Link] + delta.X,
■■■[Link],
■■■[Link] + delta.Y
■■)
■end
end)

-------------------------------------------------
-- COSMETICS (HUMANOID DESCRIPTION)
-------------------------------------------------
local FACE_ID = 7074764
local SHIRTS = {144076760, 144076759}
local PANTS = {144076511, 144076512}
local HATS = {1029025, 607702162, 439946101}

local function applyCosmetics(humanoid)


■local desc = [Link]("HumanoidDescription")
■[Link] = FACE_ID
■[Link] = SHIRTS[[Link](#SHIRTS)]
■[Link] = PANTS[[Link](#PANTS)]
■[Link] = tostring(HATS[[Link](#HATS)])
■humanoid:ApplyDescription(desc)
end

-------------------------------------------------
-- RANDOM BODY COLOR (ADDED & GROUPED)
-------------------------------------------------
local BODY_COLORS = {
■[Link](255, 219, 172),
■[Link](241, 194, 125),
■[Link](224, 172, 105),
■[Link](198, 134, 66),
■[Link](141, 85, 36)
}

local function applyRandomBodyColor(parts)


■local color = BODY_COLORS[[Link](#BODY_COLORS)]
■for _, part in ipairs(parts) do
■■[Link] = color
■end
end

-------------------------------------------------
-- GROUND SNAP
-------------------------------------------------
local function snapToGround(cf)
■local params = [Link]()
■[Link] = {character}
■[Link] = [Link]

■local result = Workspace:Raycast(


■■[Link] + [Link](0, 20, 0),
■■[Link](0, -100, 0),
■■params
■)

■if result then


■■return [Link](
■■■[Link](cf.X, [Link].Y + 3, cf.Z),
■■■[Link] + [Link]
■■)
■end

■return cf
end

-------------------------------------------------
-- NPC CREATION (R6)
-------------------------------------------------
local function createVRNPC(cf)
■local model = [Link]("Model")
■[Link] = "VR_NPC"

■local humanoid = [Link]("Humanoid")


■[Link] = [Link].R6
■[Link] = 10
■[Link] = model

■local root = [Link]("Part")


■[Link] = "HumanoidRootPart"
■[Link] = [Link](2, 2, 1)
■[Link] = 1
■[Link] = false
■[Link] = model

■local torso = [Link]("Part")


■[Link] = "Torso"
■[Link] = [Link](2, 2, 1)
■[Link] = model

■local head = [Link]("Part")


■[Link] = "Head"
■[Link] = [Link](2, 1, 1)
■[Link] = model

■local lArm = [Link]("Part")


■[Link] = "Left Arm"
■[Link] = [Link](1, 2, 1)
■[Link] = model

■local rArm = [Link]("Part")


■[Link] = "Right Arm"
■[Link] = [Link](1, 2, 1)
■[Link] = model

■-- APPLY RANDOM COLOR HERE


■applyRandomBodyColor({torso, head, lArm, rArm})

■local function joint(name, p0, p1, c0, c1)


■■local m = [Link]("Motor6D")
■■[Link] = name
■■m.Part0 = p0
■■m.Part1 = p1
■■m.C0 = c0
■■m.C1 = c1
■■[Link] = p0
■■return m
■end

■local neck = joint("Neck", torso, head, [Link](0,1,0), [Link](0,-0.5,0))


■local ls = joint("Left Shoulder", torso, lArm, [Link](-1.5,0.5,0), [Link](0,1,0))
■local rs = joint("Right Shoulder", torso, rArm, [Link](1.5,0.5,0), [Link](0,1,0))
■joint("RootJoint", root, torso, [Link](), [Link]())
■[Link] = root
■[Link] = Workspace
■model:SetPrimaryPartCFrame(snapToGround(cf))

■[Link]()
■applyCosmetics(humanoid)

■return model, humanoid, {neck = neck, ls = ls, rs = rs}


end

-------------------------------------------------
-- NPC BEHAVIOR
-------------------------------------------------
local function runVR(model, humanoid, joints)
■local root = [Link]
■local torso = [Link]

■local moveTask = [Link](function()


■■while [Link] do
■■■humanoid:MoveTo([Link] + [Link]([Link](-10,10),0,[Link](-10,10)))
■■■[Link]:Wait(2)
■■end
■end)

■local renderConn = [Link]:Connect(function()


■■if not character:FindFirstChild("HumanoidRootPart") then return end
■■local dir = ([Link] - [Link]).Unit

■■[Link] =
■■■[Link]([Link](dir.Y)*0.6, -math.atan2(dir.X,dir.Z)*0.6, 0)

■■local t = [Link]()
■■[Link] = [Link]([Link](t)*0.3,0,0)
■■[Link] = [Link]([Link](t)*0.3,0,0)
■end)

■return function()
■■renderConn:Disconnect()
■■[Link](moveTask)
■end
end

-------------------------------------------------
-- INPUT TOGGLE
-------------------------------------------------
local active = false
local npc, stopFn

[Link]:Connect(function(input, gp)
■if gp then return end
■if [Link] == [Link].G then
■■if active then
■■■if stopFn then stopFn() end
■■■if npc then npc:Destroy() end
■■■[Link] = "PRESS G TO SURPRISE"
■■■active = false
■■else
■■■npc, humanoid, joints =
■■■■createVRNPC([Link] * [Link](0,0,-10))
■■■stopFn = runVR(npc, humanoid, joints)
■■■[Link] = "SURPRISE ACTIVE"
■■■active = true
■■end
■end
end)

You might also like