Hey so i got this script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EventsFolder = ReplicatedStorage:WaitForChild("Events")
local spawnTowerEvent = EventsFolder:WaitForChild("PlaceEvent")
local ServerStorage = game:GetService("ServerStorage")
local animateTowerEvent = EventsFolder:WaitForChild("AnimateTower")
local tower = {}
function FindNearestTarget(newTower, range)
local maxDistance = 15
local nearestTarget = nil
for i, target in ipairs(workspace.Mobs:GetChildren()) do
local distance = (target.HumanoidRootPart.Position - tower.HumanoidRootPart.Position).Magnitude
if distance < range then
nearestTarget = target
range = distance
end
end
return nearestTarget
end
function tower.Attack(newTower, player)
local config = newTower.Config
local target = FindNearestTarget(newTower, config.Range.Value)
if target then
target.Humanoid:TakeDamage(config.Damage.Value)
if target.Humanoid.Health <= 0 then
player.Gold.Value += target.Humanoid.MaxHealth
end
task.wait(config.Cooldown.Value)
end
tower.Attack(newTower, player)
end
function tower.Spawn(player, name, cframe)
local TowerExists = ReplicatedStorage.Towers:FindFirstChild(name)
if TowerExists then
local newTower = TowerExists:Clone()
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
coroutine.wrap(tower.Attack)(newTower, player)
else
warn("bro what")
end
end
spawnTowerEvent.OnServerEvent:Connect(tower.Spawn)
return tower
and when i playtest the game i get this error
ServerScriptService.Main.PlaceModuleScript:55: Mobs is not a valid member of Workspace “Workspace”