Untitled
unknown
plain_text
2 years ago
2.4 kB
13
Indexable
-- Create a new ScreenGui local gui = Instance.new("ScreenGui") gui.Name = "MyGui" gui.Parent = game.Players.LocalPlayer.PlayerGui -- Create a Frame inside the ScreenGui for dragging local frame = Instance.new("Frame") frame.Name = "DraggableFrame" frame.BackgroundTransparency = 1 frame.Size = UDim2.new(0, 200, 0, 50) frame.Position = UDim2.new(0.5, -100, 0.5, -25) frame.Parent = gui -- Variables to keep track of the state and dragging local isRunning = false local isDragging = false local buttonStateText = { [true] = "Running", [false] = "Stopped" } -- Create a TextButton inside the Frame local button = Instance.new("TextButton") button.Name = "MyButton" button.Text = "Toggle" button.Size = UDim2.new(1, 0, 1, 0) button.Position = UDim2.new(0, 0, 0, 0) button.Parent = frame -- Function to repeatedly run the script with a 0.1-second delay local function runScript() while isRunning do game:GetService("ReplicatedStorage").Rafaga:FireServer() wait(0.1) end end -- Function to handle button click local function handleClick() -- Toggle the state isRunning = not isRunning -- Update the button text button.Text = buttonStateText[isRunning] -- Start or stop running the script if isRunning then spawn(runScript) end end -- Connect the handleClick function to the button's Clicked event button.MouseButton1Click:Connect(handleClick) -- Enable dragging of the gui local userGuiService = game:GetService("UserGuiService") local draggingEnabled = false local dragStartPos = nil frame.InputBegan:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseButton1 then draggingEnabled = true dragStartPos = input.Position frame.Draggable = true userGuiService:AddSelectionParent(gui) end end) frame.InputChanged:Connect(function(input) if draggingEnabled and input.UserInputType == Enum.UserInputType.MouseMovement then local dragDelta = input.Position - dragStartPos frame.Position = frame.Position + UDim2.new(0, dragDelta.X, 0, dragDelta.Y) dragStartPos = input.Position end end) frame.InputEnded:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseButton1 then draggingEnabled = false frame.Draggable = false userGuiService:RemoveSelectionGroup(gui) end end)
Editor is loading...
Leave a Comment