tomoneko

簡易リセット

Oct 28th, 2023 (edited)
696
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. -- GUIを作成します
  2. local function createButton(pos)
  3. local ScreenGui = Instance.new("ScreenGui")
  4. local Button = Instance.new("TextButton")
  5. local UserInputService = game:GetService("UserInputService")
  6.  
  7. -- プロパティを設定します
  8. ScreenGui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")
  9. Button.Parent = ScreenGui
  10. Button.Size = UDim2.new(0, 50, 0, 50)
  11. Button.Position = pos or UDim2.new(0.5, -25, 0.5, -25) -- 保存した位置を使用します
  12. Button.Text = "リセット"
  13. Button.Draggable = true
  14.  
  15. -- ボタンがクリックされたときの動作を定義します
  16. Button.MouseButton1Click:Connect(function()
  17. game.Players.LocalPlayer.Character:BreakJoints()
  18. end)
  19.  
  20. -- ドラッグ機能を追加します
  21. local dragging
  22. local dragInput
  23. local dragStart
  24. local startPos
  25.  
  26. local function update(input)
  27. local delta = input.Position - dragStart
  28. Button.Position = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y)
  29. end
  30.  
  31. Button.InputBegan:Connect(function(input)
  32. if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
  33. dragging = true
  34. dragStart = input.Position
  35. startPos = Button.Position
  36.  
  37. input.Changed:Connect(function()
  38. if input.UserInputState == Enum.UserInputState.End then
  39. dragging = false
  40. end
  41. end)
  42. end
  43. end)
  44.  
  45. Button.InputChanged:Connect(function(input)
  46. if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
  47. dragInput = input
  48. end
  49. end)
  50.  
  51. UserInputService.InputChanged:Connect(function(input)
  52. if input == dragInput and dragging then
  53. update(input)
  54. end
  55. end)
  56.  
  57. return Button -- ボタンの参照を返します
  58. end
  59.  
  60. -- プレイヤーがリスポーンしたときにボタンを再作成します
  61. local buttonPos
  62. game.Players.LocalPlayer.CharacterAdded:Connect(function()
  63. local button = createButton(buttonPos)
  64.  
  65. -- ボタンが移動したときに位置を保存します
  66. button.Changed:Connect(function(prop)
  67. if prop == "Position" then
  68. buttonPos = button.Position
  69. end
  70. end)
  71. end)
  72.  
  73. -- 初期化時にボタンを作成します
  74. createButton()
Advertisement
Add Comment
Please, Sign In to add comment