then put it back in serverstorage and test it
1 Like
again it still doesn’t work
any errors relating to entityspawner or playerunithandler? and can you show me full code for each scripts now please?
1 Like
Here you go
EntitySpawner
local EnemyHandler = require(script.EnemyHandler)
local playerUnitHandler = require(script.PlayerUnitHandler)
local Map = game.Workspace["Tower Defense Map"]
local Bases = Map.Bases
local EnemyBase = game.Workspace["Tower Defense Map"].Bases.EnemyBase
local PlayerBase = game.Workspace["Tower Defense Map"].Bases.PlayerBase
local Enemies = Map.Enemies
playerUnitHandler.createUnit({
Damage = 1,
Range = 15,
AttackDelay = 2
})
for i = 1, 10 do
EnemyHandler.createEnemy({
Health = 1,
})
task.wait(2)
end
PlayerUnitHandler
local PUnitHeandler = {List={}}
local ServerStorage = game.ServerStorage
local Map = game.Workspace["Tower Defense Map"]
local Units = Map.Units
local Enemies = Map.Enemies
local function getClosetEnemy(Range)
local ClosestEnemy, Distance = nil, math.huge
for _, Enemy in next, Enemies:GetChildren() do
local Distance = (Unit.Position - Enemy.Position).Magnitude
if Distance <= Distance then
ClosestEnemy = Enemy
ClosestDistance = Distance
end
end
return ClosestEnemy, Distance
end
PUnitHeandler.createUnit = function(Details)
local Unit = ServerStorage.Unit:Clone()
Unit.Parent = Units
Unit.Radius.Size = Vector3.new(Details.Range, Details.Range, Details.Range)
Unit.Radius.Position = Unit.Position
Unit.Radius.Transparency = 1
task.spawn(function()
while Unit:IsDescendantOf(workspace) do
local Enemy = getClosetEnemy(Unit, Details.Range)
if not Enemy then continue end
print(Enemy)
task.wait()
end
end)
end
return PUnitHeandler
I even made a whole new game to see whether or not it was the game and it still doesn’t work
what about EnemyHandler ?
limit
all the scripts were at the beginning of the post but here
local EHandler = {List={}}
local HttpService = game:GetService("HttpService")
local TweenService = game:GetService("TweenService")
local ServerStorage = game.ServerStorage
local Map = game.Workspace["Tower Defense Map"]
local WalkPoints = Map.Movement
local Enemies = Map.Enemies
local PlayerBase = Map.Bases.PlayerBase
local function OnFinish(Enemy)
Enemy.Body:Destroy();
PlayerBase.Health.Value -= Enemy.Details.Damage
end
local MoveEnemy
MoveEnemy = function(Enemy)
if not(WalkPoints:FindFirstChild(Enemy.CurrentPoint)) then
return OnFinish()
end
local Info = TweenInfo.new(2);
TweenService:Create(Enemy.Body, TweenInfo.new(2,Enum.EasingStyle.Linear), {
Position = WalkPoints[tostring(Enemy.CurrentPoint)].Position
}):Play()
Enemy.CurrentPoint += 1
task.delay(2, MoveEnemy, Enemy)
end
EHandler.doDamage = function(EntityGUID, Damage)
local Entity = EHandler.List[EntityGUID]
if not Entity then return warn('GUID not found in Entity List') end
Entity.Health -= Damage
if Entity.Health <= 0 then
Entity.Body:Destroy()
end
end
EHandler.createEnemy = function(Details)
-- Will later be used to determine health, type, and etc...
local GUID = HttpService:GenerateGUID(false)
local Enemy = ServerStorage.Enemy:Clone()
Enemy.Parent = Enemies
Enemy.Position = WalkPoints["1"].Position
Enemy.Name = GUID
local EnemyDetails = {
Body = Enemy,
CurrentPoint = 1,
Details = Details,
OnDamage = function(Damage)end,
}
--Future..
EHandler.List[GUID] = EnemyDetails
MoveEnemy(EnemyDetails)
return EnemyDetails
end
return EHandler
can you put a print under
playerUnitHandler.createUnit({
Damage = 1,
Range = 15,
AttackDelay = 2
})
and tell me if it runs
it worked
18:23:39.510 this is a test - Server - EntitySpawner:12
I placed it everywhere and this is what it comes back to
Put a print statement under here and see if it prints, also check if Enemy is cancollide true
1 Like