Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local UserInputService = game:GetService("UserInputService")
- local LocalPlayer = Players.LocalPlayer
- -- GUI elements
- local screenGui = Instance.new("ScreenGui")
- screenGui.Parent = LocalPlayer.PlayerGui
- screenGui.Name = "TowerSpawnerGUI" --Added name for easier management
- local mainFrame = Instance.new("Frame")
- mainFrame.Parent = screenGui
- mainFrame.Size = UDim2.new(0.25, 0, 0.15, 0) --Increased size for better visibility
- mainFrame.Position = UDim2.new(0.375, 0, 0.425, 0) --Centered
- mainFrame.BackgroundColor3 = Color3.new(0,0,0) --Black background
- mainFrame.BorderColor3 = Color3.new(0.2, 0.2, 0.2) --Darker border
- mainFrame.BorderSizePixel = 2
- local textBox = Instance.new("TextBox")
- textBox.Parent = mainFrame
- textBox.Size = UDim2.new(0.8, 0, 0.4, 0)
- textBox.Position = UDim2.new(0.1, 0, 0.1, 0)
- textBox.PlaceholderText = "Tower Type (e.g., Time)"
- textBox.BackgroundColor3 = Color3.new(0.1, 0.1, 0.1)
- textBox.TextColor3 = Color3.new(1, 1, 1) --White text
- textBox.BorderColor3 = Color3.new(0.2, 0.2, 0.2)
- local button = Instance.new("TextButton")
- button.Parent = mainFrame
- button.Size = UDim2.new(0.8, 0, 0.4, 0)
- button.Position = UDim2.new(0.1, 0, 0.55, 0)
- button.Text = "Spawn Tower"
- button.BackgroundColor3 = Color3.new(0.2, 0.2, 0.2)
- button.TextColor3 = Color3.new(1, 1, 1) --White text
- button.BorderColor3 = Color3.new(0.2, 0.2, 0.2)
- --Improved Drag functionality with better error handling.
- local dragging = false
- local startPos
- local dragOffset
- mainFrame.InputBegan:Connect(function(input, gameProcessedEvent)
- if input.UserInputType == Enum.UserInputType.Touch and not gameProcessedEvent then
- dragging = true
- startPos = input.Position
- dragOffset = mainFrame.Position - UDim2.new(0, input.Position.X, 0, input.Position.Y)
- end
- end)
- mainFrame.InputEnded:Connect(function(input)
- if input.UserInputType == Enum.UserInputType.Touch then
- dragging = false
- end
- end)
- UserInputService.InputChanged:Connect(function(input)
- if dragging and input.UserInputType == Enum.UserInputType.Touch then
- mainFrame.Position = dragOffset + UDim2.new(0, input.Position.X, 0, input.Position.Y)
- end
- end)
- -- Event handling (modified to append "0")
- button.MouseButton1Click:Connect(function()
- local towerType = textBox.Text
- towerType = towerType == "" and "Default" or towerType .. "0"
- local character = LocalPlayer.Character
- if character == nil then
- print("Character not found. Waiting...")
- character = LocalPlayer.CharacterAdded:Wait()
- end
- local humanRootPart = character:FindFirstChild("HumanoidRootPart")
- if humanRootPart == nil then
- warn("HumanoidRootPart not found!")
- return
- end
- local args = {
- [1] = towerType,
- [2] = humanRootPart.CFrame,
- [3] = 0
- }
- local event = ReplicatedStorage:WaitForChild("Events"):WaitForChild("SpawnTower")
- if event then
- event:FireServer(unpack(args))
- else
- warn("SpawnTower event not found!")
- end
- end)
- textBox.FocusLost:Connect(function()
- if textBox:IsFocused() then return end
- button.MouseButton1Click:Invoke()
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement