local Players = game:GetService("Players") local RunService = game:GetService("RunService") local ReplicatedStorage = game:GetService("ReplicatedStorage") -- Create RemoteEvent for server communication local stickToggleEvent = Instance.new("RemoteEvent") stickToggleEvent.Name = "StickToggleEvent" stickToggleEvent.Parent = ReplicatedStorage local player = Players.LocalPlayer local stickEnabled = false local stickOffset = Vector3.new(0, -5, 0) -- Offset below the player’s feet -- Function to create GUI local function createStickGui() local screenGui = Instance.new("ScreenGui") screenGui.Name = "StickToggleGui" screenGui.ResetOnSpawn = false -- This prevents it from disappearing automatically screenGui.Parent = player:WaitForChild("PlayerGui") local toggleButton = Instance.new("TextButton") toggleButton.Size = UDim2.new(0, 100, 0, 30) toggleButton.Position = UDim2.new(0, 10, 0, 10) toggleButton.Text = "Toggle Stick" toggleButton.Parent = screenGui toggleButton.MouseButton1Click:Connect(function() stickEnabled = not stickEnabled stickToggleEvent:FireServer(stickEnabled) end) end -- Ensure GUI exists on start if not player.PlayerGui:FindFirstChild("StickToggleGui") then createStickGui() end -- Variables for character local character = player.Character or player.CharacterAdded:Wait() local humanoidRootPart = character:WaitForChild("HumanoidRootPart") -- Function to get the closest player local function getClosestPlayer(position) local closestPlayer = nil local shortestDistance = math.huge for _, p in ipairs(Players:GetPlayers()) do if p ~= player and p.Character and p.Character:FindFirstChild("HumanoidRootPart") then local distance = (p.Character.HumanoidRootPart.Position - position).magnitude if distance < shortestDistance then shortestDistance = distance closestPlayer = p end end end return closestPlayer end -- Function to stick to the nearest player local function updateCharacterPosition() if stickEnabled and humanoidRootPart.Parent then local closestPlayer = getClosestPlayer(humanoidRootPart.Position) if closestPlayer and closestPlayer.Character and closestPlayer.Character:FindFirstChild("HumanoidRootPart") then local targetPosition = closestPlayer.Character.HumanoidRootPart.Position local newPosition = targetPosition + stickOffset humanoidRootPart.CFrame = CFrame.new(newPosition, newPosition + Vector3.new(0,1,0)) end end end RunService.Heartbeat:Connect(updateCharacterPosition) -- Re-parent GUI on respawn player.CharacterAdded:Connect(function(char) character = char humanoidRootPart = character:WaitForChild("HumanoidRootPart") if not player.PlayerGui:FindFirstChild("StickToggleGui") then createStickGui() end end)