local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PhysicsService = game:GetService("PhysicsService")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local modules = ReplicatedStorage:WaitForChild("Modules")
local Health = require(modules:WaitForChild("Health"))
local Coins = [Link]:WaitForChild("Coins")
local Events = ReplicatedStorage:WaitForChild("Events")
local Functions = ReplicatedStorage:WaitForChild("Functions")
local SpawnTowerFunction = Functions:WaitForChild("SpawnTower")
local RequestTowerFunction = Functions:WaitForChild("RequestTower")
local ChangeTowerModeFunction = Functions:WaitForChild("ChangeTowerMode")
local SellTowerFunction = Functions:WaitForChild("SellTower")
local towers = ReplicatedStorage:WaitForChild("Towers")
local camera = [Link]
local gui = [Link]
local map = workspace:WaitForChild("Grassland")
local base = map:WaitForChild("Base")
local info = workspace:WaitForChild("Info")
local hoveredInstance = nil
local selectedTower = nil
local towerToSpawn = nil
local canPlace = false
local Rotation = 0
local placedTowers = 0
local maxTowers = 25
local function setupGUI()
[Link](base, [Link])
[Link]:Connect(function(mob)
[Link](mob)
end)
[Link]:Connect(function(change)
[Link] = change
end)
[Link]:Connect(function(change)
[Link] = "Wave: "..change
if change == " " then
[Link] = false
else
[Link] = true
end
end)
[Link]:Connect(function(change)
[Link] = "$"..change
end)
[Link] = "$"..[Link]
end
setupGUI()
local function MouseRaycast(blacklist)
local mousePosition = UserInputService:GetMouseLocation()
local mouseRay = camera:ViewportPointToRay(mousePosition.X, mousePosition.Y)
local raycastParams = [Link]()
[Link] = [Link]
[Link] = blacklist
local raycastResult = workspace:Raycast([Link], [Link] *
1000, raycastParams)
return raycastResult
end
local function CreateRangeCircle(tower, placeHolder)
local range = [Link]
local height = ([Link].Y / 2) + tower["Left Leg"].Size.Y - 2
local offset = [Link](0, -height, 0)
local p = [Link]("Part")
[Link] = "Range"
[Link] = [Link]
[Link] = [Link]
[Link] = 0.9
[Link] = [Link](0.2, range * 2, range * 2)
[Link] = [Link]
[Link] = [Link]
[Link] = [Link] * offset * [Link](0, 0,
[Link](90))
[Link] = false
if placeHolder then
[Link] = false
local weld = [Link]("WeldConstraint")
weld.Part0 = p
weld.Part1 = [Link]
[Link] = p
[Link] = tower
else
[Link] = [Link]
[Link] = true
end
end
local function RemovePlaceholderTower()
if towerToSpawn ~= nil then
towerToSpawn:Destroy()
towerToSpawn = nil
Rotation = 0
end
end
local function AddPlaceholderTower(name)
local towerExists = towers:FindFirstChild(name)
if towerExists then
RemovePlaceholderTower()
towerToSpawn = towerExists:Clone()
[Link] = workspace
CreateRangeCircle(towerToSpawn, true)
for i, object in ipairs(towerToSpawn:GetDescendants()) do
if object:IsA("BasePart") then
[Link] = "Towers"
if [Link] ~= "Range" then
[Link] = [Link]
[Link] = 0.3
else
return
end
end
end
end
end
local function colorPlaceholderTower(color)
for i, object in ipairs(towerToSpawn:GetDescendants()) do
if object:IsA("BasePart") and [Link] ~= "Range" then
[Link] = color
end
end
end
[Link] = placedTowers.." / "..maxTowers.. " Placed"
for i, tower in pairs(towers:GetChildren()) do
if tower:IsA("Model") then
local button = [Link]:Clone()
local config = tower:WaitForChild("Configuration")
[Link] = [Link]
[Link] = [Link]
[Link] = true
[Link] = "$"..[Link]
[Link] = [Link]
[Link] = [Link]
[Link]:Connect(function()
local allowedToSpawn =
RequestTowerFunction:InvokeServer([Link])
if allowedToSpawn then
AddPlaceholderTower([Link])
end
end)
end
end
local function toggleTowerInfo()
[Link]:ClearAllChildren()
[Link] = placedTowers.." / "..maxTowers.. " Placed"
if selectedTower then
[Link] = true
local config = [Link]
[Link] = [Link]
[Link] = [Link]
[Link] = [Link]
[Link] = [Link]
[Link] = [Link]
[Link] = [Link].."'s"
if [Link] == [Link] then
[Link] = true
local upgradeTower = config:FindFirstChild("Upgrade")
if upgradeTower then
[Link] = true
[Link] = "Upgrade: ($"
.. [Link] .. ")"
else
[Link] = false
end
end
CreateRangeCircle(selectedTower, false)
else
[Link] = false
end
end
[Link]:Connect(function()
if selectedTower then
local modeChangeSuccess =
ChangeTowerModeFunction:InvokeServer(selectedTower)
if modeChangeSuccess then
ChangeTowerModeFunction:InvokeServer()
end
end
end)
[Link]:Connect(function()
if selectedTower then
local upgradeTower = [Link]
local allowedToUpgrade =
RequestTowerFunction:InvokeServer([Link])
if allowedToUpgrade then
selectedTower =
SpawnTowerFunction:InvokeServer([Link],
[Link], selectedTower)
toggleTowerInfo()
end
end
end)
[Link]:Connect(function()
if selectedTower then
local soldTower = SellTowerFunction:InvokeServer(selectedTower)
if soldTower then
selectedTower = nil
placedTowers = placedTowers -1
toggleTowerInfo()
end
end
end)
[Link]:Connect(function(input, processed)
if processed then
return
end
if towerToSpawn ~= nil then
if [Link] == [Link].MouseButton1 then
if canPlace then
local placedTower =
SpawnTowerFunction:InvokeServer([Link], [Link])
if placedTower then
placedTowers += 1
RemovePlaceholderTower()
toggleTowerInfo()
end
end
elseif [Link] == [Link].R then
Rotation += 90
end
elseif hoveredInstance and [Link] ==
[Link].MouseButton1 then
local model = hoveredInstance:FindFirstAncestorOfClass("Model")
if model and [Link] == [Link] then
selectedTower = model
else
selectedTower = nil
end
toggleTowerInfo()
end
end)
[Link]:Connect(function()
local result = MouseRaycast({towerToSpawn})
if result and [Link] then
if towerToSpawn then
hoveredInstance = nil
if [Link] == "TowerArea" then
canPlace = true
colorPlaceholderTower([Link](0, 1, 0))
else
canPlace = false
colorPlaceholderTower([Link](1,0,0))
end
local x = [Link]([Link].X)
local y = [Link]([Link].Y +
[Link] + ([Link].Y / 2))
local z = [Link]([Link].Z)
local cframe = [Link](x,y,z) *
[Link](0,[Link](Rotation), 0)
towerToSpawn:SetPrimaryPartCFrame(cframe)
else
hoveredInstance = [Link]
end
else
hoveredInstance = nil
end
end)