-- LocalScript (place in StarterPlayerScripts)
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local player = [Link]
local PlayerGui = player:WaitForChild("PlayerGui")
-- Create ScreenGui
local screenGui = [Link]("ScreenGui")
[Link] = "FButtonGui"
[Link] = false
[Link] = PlayerGui
-- Create TextButton
local button = [Link]("TextButton")
[Link] = [Link](0, 50, 0, 50) -- 50x50 pixels
[Link] = [Link](0.5, -25, 0.5, -25) -- Centered
[Link] = "F"
button.BackgroundColor3 = [Link](255, 0, 0)
[Link] = true
[Link] = screenGui
[Link] = true -- Needed for dragging
-- Make button draggable
local dragging = false
local dragInput, mousePos, framePos
local function update(input)
local delta = [Link] - mousePos
[Link] = [Link](
0,
[Link](framePos.X + delta.X, 0, [Link].X
- [Link].X),
0,
[Link](framePos.Y + delta.Y, 0, [Link].Y
- [Link].Y)
)
end
[Link]:Connect(function(input)
if [Link] == [Link].MouseButton1 then
dragging = true
mousePos = [Link]
framePos = [Link]
[Link]:Connect(function()
if [Link] == [Link] then
dragging = false
end
end)
end
end)
[Link]:Connect(function(input)
if [Link] == [Link] then
dragInput = input
end
end)
[Link]:Connect(function(input)
if input == dragInput and dragging then
update(input)
end
end)
-- Fire "F" key when button clicked
button.MouseButton1Click:Connect(function()
-- This simulates pressing "F" via the VirtualInputManager
-- Note: Some games may not accept simulated keypresses due to
filtering/security
local VirtualInputManager = game:GetService("VirtualInputManager")
VirtualInputManager:SendKeyEvent(true, [Link].F, false, game)
VirtualInputManager:SendKeyEvent(false, [Link].F, false, game)
end)