function tower.Spawn(player, name,cframe,previous)
local allow = tower.Chexpawn(player,name)
local newtower
if previous then
previous:Destroy()
newtower = game.ReplicatedStorage.towers.Upgrades[name]:Clone()
else
newtower = game.ReplicatedStorage.towers[name]:Clone()
end
if allow then
newtower.HumanoidRootPart.CFrame = cframe
newtower.Parent = workspace.towers
newtower.HumanoidRootPart:SetNetworkOwner(nil)
for i, object in ipairs(newtower:GetDescendants()) do
if object:IsA("BasePart") then
object.CollisionGroup = "tower"
end
end
player.money.Value -= newtower.Configuration.cost.Value
player.placedtowers.Value += 1
coroutine.wrap(tower.Attack(newtower, player))
return newtower
else
warn("tower is not real")
return false
end
end
function tower.Chexpawn(player, name)
local towerexists = repstor.towers:FindFirstChild(name,true)
if towerexists then
if towerexists.Configuration.cost.Value <= player.money.Value then
if player.placedtowers.Value < maxtowers then
return true
else
warn("tower limit")
end
else
warn("poor")
end
else
warn("faker")
end
return false
end