--// Services
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
--// Local player and PlayerGui
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
--// Create a persistent ScreenGui (persists across respawns)
local screenGui = Instance.new("ScreenGui")
screenGui.Name = "DeployGui"
screenGui.ResetOnSpawn = false
screenGui.Parent = playerGui
--// Create a beautiful, draggable Deploy button
local deployButton = Instance.new("TextButton")
deployButton.Name = "DeployButton"
deployButton.Size = UDim2.new(0, 220, 0, 60)
deployButton.Position = UDim2.new(0.5, -110, 0.1, 0)
deployButton.Text = "Deploy"
deployButton.Font = Enum.Font.GothamBold
deployButton.TextSize = 28
deployButton.TextColor3 = Color3.new(1, 1, 1)
deployButton.BackgroundColor3 = Color3.fromRGB(30, 144, 255) -- DodgerBlue shade
deployButton.BorderSizePixel = 0
deployButton.Active = true
deployButton.Draggable = true
deployButton.Parent = screenGui
-- Apply a rounded corner effect using UICorner
local uicorner = Instance.new("UICorner")
uicorner.CornerRadius = UDim.new(0, 20)
uicorner.Parent = deployButton
-- Apply a smooth gradient effect using UIGradient
local uigradient = Instance.new("UIGradient")
uigradient.Color = ColorSequence.new({
ColorSequenceKeypoint.new(0, Color3.fromRGB(65, 105, 225)), -- RoyalBlue
ColorSequenceKeypoint.new(1, Color3.fromRGB(30, 144, 255)) -- DodgerBlue
})
uigradient.Rotation = 45
uigradient.Parent = deployButton
--------------------------------------------------------------------------------
-- Variables to manage deploy state.
--------------------------------------------------------------------------------
local deployed = false -- Whether deploy mode is active.
local savedCFrame = nil -- Stores the player's CFrame at deploy time.
local loopConnection = nil -- Connection for the RunService loop.
--------------------------------------------------------------------------------
-- Function: startDeployLoop(character)
-- Starts a loop that continuously teleports the player's character to the saved position.
--------------------------------------------------------------------------------
local function startDeployLoop(character)
return RunService.Stepped:Connect(function()
if character and savedCFrame then
local hrp = character:FindFirstChild("HumanoidRootPart")
if hrp then
hrp.CFrame = savedCFrame
end
end
end)
end
--------------------------------------------------------------------------------
-- Function: deploy()
-- Captures the current position, teleports the player there, and starts the loop.
--------------------------------------------------------------------------------
local function deploy()
local character = player.Character or player.CharacterAdded:Wait()
local hrp = character:WaitForChild("HumanoidRootPart", 5)
savedCFrame = hrp.CFrame -- Save the current position.
hrp.CFrame = savedCFrame -- Immediate teleport.
loopConnection = startDeployLoop(character)
deployed = true
deployButton.Text = "UnDeploy"
end
--------------------------------------------------------------------------------
-- Function: undeploy()
-- Stops the deploy mode and disconnects the teleport loop.
--------------------------------------------------------------------------------
local function undeploy()
deployed = false
deployButton.Text = "Deploy"
if loopConnection then
loopConnection:Disconnect()
loopConnection = nil
end
end
--------------------------------------------------------------------------------
-- Button click event to toggle deploy mode.
--------------------------------------------------------------------------------
deployButton.MouseButton1Click:Connect(function()
if not deployed then
deploy()
else
undeploy()
end
end)
--------------------------------------------------------------------------------
-- Reapply deploy mode when the player's character respawns.
--------------------------------------------------------------------------------
player.CharacterAdded:Connect(function(character)
if deployed and savedCFrame then
local hrp = character:WaitForChild("HumanoidRootPart", 5)
hrp.CFrame = savedCFrame -- Immediately restore to saved deploy location.
if loopConnection then
loopConnection:Disconnect()
end
loopConnection = startDeployLoop(character)
end
end)-- DEPLOY NICE :))
Comments
NEW SCRIPT UPLOADED!