Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- GUIを作成します
- local function createButton(pos)
- local ScreenGui = Instance.new("ScreenGui")
- local Button = Instance.new("TextButton")
- local UserInputService = game:GetService("UserInputService")
- -- プロパティを設定します
- ScreenGui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")
- Button.Parent = ScreenGui
- Button.Size = UDim2.new(0, 50, 0, 50)
- Button.Position = pos or UDim2.new(0.5, -25, 0.5, -25) -- 保存した位置を使用します
- Button.Text = "リセット"
- Button.Draggable = true
- -- ボタンがクリックされたときの動作を定義します
- Button.MouseButton1Click:Connect(function()
- game.Players.LocalPlayer.Character:BreakJoints()
- end)
- -- ドラッグ機能を追加します
- local dragging
- local dragInput
- local dragStart
- local startPos
- local function update(input)
- local delta = input.Position - dragStart
- Button.Position = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y)
- end
- Button.InputBegan:Connect(function(input)
- if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
- dragging = true
- dragStart = input.Position
- startPos = Button.Position
- input.Changed:Connect(function()
- if input.UserInputState == Enum.UserInputState.End then
- dragging = false
- end
- end)
- end
- end)
- Button.InputChanged:Connect(function(input)
- if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
- dragInput = input
- end
- end)
- UserInputService.InputChanged:Connect(function(input)
- if input == dragInput and dragging then
- update(input)
- end
- end)
- return Button -- ボタンの参照を返します
- end
- -- プレイヤーがリスポーンしたときにボタンを再作成します
- local buttonPos
- game.Players.LocalPlayer.CharacterAdded:Connect(function()
- local button = createButton(buttonPos)
- -- ボタンが移動したときに位置を保存します
- button.Changed:Connect(function(prop)
- if prop == "Position" then
- buttonPos = button.Position
- end
- end)
- end)
- -- 初期化時にボタンを作成します
- createButton()
Advertisement
Add Comment
Please, Sign In to add comment