Advertisement
Bacon_Script

Untitled

Jan 23rd, 2025
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  3. local UserInputService = game:GetService("UserInputService")
  4. local LocalPlayer = Players.LocalPlayer
  5.  
  6. -- GUI elements
  7. local screenGui = Instance.new("ScreenGui")
  8. screenGui.Parent = LocalPlayer.PlayerGui
  9. screenGui.Name = "TowerSpawnerGUI" --Added name for easier management
  10.  
  11. local mainFrame = Instance.new("Frame")
  12. mainFrame.Parent = screenGui
  13. mainFrame.Size = UDim2.new(0.25, 0, 0.15, 0) --Increased size for better visibility
  14. mainFrame.Position = UDim2.new(0.375, 0, 0.425, 0) --Centered
  15. mainFrame.BackgroundColor3 = Color3.new(0,0,0) --Black background
  16. mainFrame.BorderColor3 = Color3.new(0.2, 0.2, 0.2) --Darker border
  17. mainFrame.BorderSizePixel = 2
  18.  
  19.  
  20. local textBox = Instance.new("TextBox")
  21. textBox.Parent = mainFrame
  22. textBox.Size = UDim2.new(0.8, 0, 0.4, 0)
  23. textBox.Position = UDim2.new(0.1, 0, 0.1, 0)
  24. textBox.PlaceholderText = "Tower Type (e.g., Time)"
  25. textBox.BackgroundColor3 = Color3.new(0.1, 0.1, 0.1)
  26. textBox.TextColor3 = Color3.new(1, 1, 1) --White text
  27. textBox.BorderColor3 = Color3.new(0.2, 0.2, 0.2)
  28.  
  29.  
  30. local button = Instance.new("TextButton")
  31. button.Parent = mainFrame
  32. button.Size = UDim2.new(0.8, 0, 0.4, 0)
  33. button.Position = UDim2.new(0.1, 0, 0.55, 0)
  34. button.Text = "Spawn Tower"
  35. button.BackgroundColor3 = Color3.new(0.2, 0.2, 0.2)
  36. button.TextColor3 = Color3.new(1, 1, 1) --White text
  37. button.BorderColor3 = Color3.new(0.2, 0.2, 0.2)
  38.  
  39.  
  40. --Improved Drag functionality with better error handling.
  41. local dragging = false
  42. local startPos
  43. local dragOffset
  44.  
  45. mainFrame.InputBegan:Connect(function(input, gameProcessedEvent)
  46. if input.UserInputType == Enum.UserInputType.Touch and not gameProcessedEvent then
  47. dragging = true
  48. startPos = input.Position
  49. dragOffset = mainFrame.Position - UDim2.new(0, input.Position.X, 0, input.Position.Y)
  50. end
  51. end)
  52.  
  53. mainFrame.InputEnded:Connect(function(input)
  54. if input.UserInputType == Enum.UserInputType.Touch then
  55. dragging = false
  56. end
  57. end)
  58.  
  59. UserInputService.InputChanged:Connect(function(input)
  60. if dragging and input.UserInputType == Enum.UserInputType.Touch then
  61. mainFrame.Position = dragOffset + UDim2.new(0, input.Position.X, 0, input.Position.Y)
  62. end
  63. end)
  64.  
  65.  
  66. -- Event handling (modified to append "0")
  67. button.MouseButton1Click:Connect(function()
  68. local towerType = textBox.Text
  69. towerType = towerType == "" and "Default" or towerType .. "0"
  70.  
  71. local character = LocalPlayer.Character
  72. if character == nil then
  73. print("Character not found. Waiting...")
  74. character = LocalPlayer.CharacterAdded:Wait()
  75. end
  76.  
  77. local humanRootPart = character:FindFirstChild("HumanoidRootPart")
  78. if humanRootPart == nil then
  79. warn("HumanoidRootPart not found!")
  80. return
  81. end
  82.  
  83. local args = {
  84. [1] = towerType,
  85. [2] = humanRootPart.CFrame,
  86. [3] = 0
  87. }
  88.  
  89. local event = ReplicatedStorage:WaitForChild("Events"):WaitForChild("SpawnTower")
  90. if event then
  91. event:FireServer(unpack(args))
  92. else
  93. warn("SpawnTower event not found!")
  94. end
  95. end)
  96.  
  97.  
  98. textBox.FocusLost:Connect(function()
  99. if textBox:IsFocused() then return end
  100. button.MouseButton1Click:Invoke()
  101. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement