#Attempting to replace my Tower Defense game config files with a modulescript. need help
32 messages · Page 1 of 1 (latest)
function tower.Spawn(player, name, cframe, previous)
local allowedToSpawn = tower.CheckSpawn(player, name)
if allowedToSpawn then
local towerspawn
if previous then
previous:Destroy()
towerspawn = RSS.Towers.Upgrades[name]:Clone()
else
towerspawn = RSS.Towers[name]:Clone()
player.placedTowers.Value += 1
end
local ownerValue = Instance.new('StringValue')
ownerValue.Name = 'Owner'
ownerValue.Value = player.Name
ownerValue.Parent = towerspawn
local towerspawn = RSS.Towers[name]:Clone()
towerspawn.HumanoidRootPart.CFrame = cframe
towerspawn.Parent = workspace["Towers Placed"]
for i, object in ipairs(towerspawn:GetDescendants()) do
if object:IsA('BasePart') then
object.CollisionGroup = "tower"
tower.Optimize(towerspawn)
end
end
player.Gold.Value -= towerStats[towerspawn.Name]['Price']
coroutine.wrap(tower.Attack)(towerspawn, player) -- line 179
else
warn('tower doesnt exist:', name)
end
end
function tower.FindTarget(towerspawn)
local towerData = towerStats[towerspawn.Name]
local range = towerData.Range -- line 110
local targetMode = towerData.TargetMode
local bestTarget = nil
local bestDistance = nil
local bestWaypoint = nil
local bestHealth = nil
for i, mob in ipairs(workspace.Mobs:GetChildren()) do
local distanceToMob = (mob.HumanoidRootPart.Position - towerspawn.HumanoidRootPart.Position).Magnitude
local distanceToWaypoint = (mob.HumanoidRootPart.Position - map.Waypoints[mob.MovingTo.Value].Position).Magnitude
if distanceToMob <= range then
if targetMode == "Nearest" then
if distanceToMob < bestDistance then
bestDistance = distanceToMob
bestTarget = mob
elseif targetMode == 'First' then
if not bestWaypoint or mob.MovingTo.Value >= bestWaypoint then
bestWaypoint = mob.MovingTo.Value
if not bestDistance or distanceToWaypoint < bestDistance then
bestDistance = distanceToWaypoint
bestTarget = mob
end
end
end
end
end
end
return bestTarget
end```
Noob = {
Price = 1,
Damage = 1,
Cooldown = 0,
Range = 1000,
Stealth = true,
TargetMode = '',
Upgrade1 = 'Noob100',
Upgrade2 = 'Noob010',
Upgrade3 = 'Noob001',
Special = 'None',
Picture = 'rbxassetid://16379612331', -- add picture id here
Attack = '', -- add attackanim id here
Idle = '' -- add idleanim id here
}
}
return towerStats
ServerScriptService.Main.Tower:178: ServerScriptService.Main.Tower:110: attempt to index nil with 'Range'
my error message
but towerData is already towerStats[towerspawn.Name]
What did u get
it gave me the table
maybe i could fix it by just adding a name into the table