Tower Defense game doesn't spawn enemy anymore

hello, I’m currently making a Tower defense game the problem is that the Enemy doesn’t spawn at all when I added tower health (Incomplete). The enemies are supposed to be in the Enemies folder, they were working previously but all of a sudden the enemies don’t spawn at all anymore.

SCREENSHOTS

image
image
image

SCRIPTS

EntitySpawner
local EnemyHandler = require(script.EnemyHandler)



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

PlayerBase.Touched:Connect(function(Inst)
	if Inst.Parent == Enemies then 
		print(Inst.Name)
	end
end)

for i = 1,10 do 
	local Enemy = EnemyHandler.createEnemy()
	task.wait(math.random(1, 2))
end

EnemyHandler
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.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
	}
	
	--Future..
	EHandler.List[GUID] = EnemyDetails
	MoveEnemy(EnemyDetails)
	
	return EnemyDetails
end

return EHandler

OUTPUT

(if you don’t want to read threw all this the only thing that isn’t working are the Nichirins which is for another game I’m working on)

00:35:15.706  cloud_340936329.GUIEditor.PluginTool:4: attempt to call a nil value  -  Server
  00:35:15.707  Stack Begin  -  Studio
  00:35:15.707  Script 'cloud_340936329.GUIEditor.PluginTool', Line 4  -  Studio
  00:35:15.707  Stack End  -  Studio
  00:35:15.707  Requested module experienced an error while loading  -  Server
  00:35:15.707  Stack Begin  -  Studio
  00:35:15.707  Script 'cloud_340936329.GUIEditor.Plugin', Line 20  -  Studio
  00:35:15.707  Stack End  -  Studio
  00:35:16.413  Combat is not a valid member of ReplicatedStorage "ReplicatedStorage"  -  Server - M2:1
  00:35:16.413  Stack Begin  -  Studio
  00:35:16.413  Script 'Workspace.Model.Nichirins.Katana.Combat.M2', Line 1  -  Studio - M2:1
  00:35:16.413  Stack End  -  Studio
  00:35:16.415  Combat is not a valid member of ReplicatedStorage "ReplicatedStorage"  -  Server - Script:2
  00:35:16.415  Stack Begin  -  Studio
  00:35:16.415  Script 'Workspace.Model.Nichirins.Katana.Combat.RemoteEvent.Script', Line 2  -  Studio - Script:2
  00:35:16.415  Stack End  -  Studio
  00:35:16.417  Combat is not a valid member of ReplicatedStorage "ReplicatedStorage"  -  Server - Script:2
  00:35:16.417  Stack Begin  -  Studio
  00:35:16.417  Script 'Workspace.Model.Nichirins.Katana.Combat.RemoteEvent.Script', Line 2  -  Studio - Script:2
  00:35:16.417  Stack End  -  Studio
  00:35:16.419  Workspace.Script:6: Expected identifier when parsing expression, got ')'  -  Studio - Script:6
  00:35:16.422  Combat is not a valid member of ReplicatedStorage "ReplicatedStorage"  -  Server - M2:1
  00:35:16.422  Stack Begin  -  Studio
  00:35:16.423  Script 'Workspace.Model.Nichirins.Katana.Combat.M2', Line 1  -  Studio - M2:1
  00:35:16.423  Stack End  -  Studio
  00:35:16.424  Combat is not a valid member of ReplicatedStorage "ReplicatedStorage"  -  Server - Script:2
  00:35:16.425  Stack Begin  -  Studio
  00:35:16.425  Script 'Workspace.Model.Nichirins.Katana.Combat.RemoteEvent.Script', Line 2  -  Studio - Script:2
  00:35:16.425  Stack End  -  Studio
  00:35:16.430  Combat is not a valid member of ReplicatedStorage "ReplicatedStorage"  -  Server - M2:1
  00:35:16.430  Stack Begin  -  Studio
  00:35:16.430  Script 'Workspace.Model.Nichirins.Katana.Combat.M2', Line 1  -  Studio - M2:1
  00:35:16.430  Stack End  -  Studio
  00:35:16.433  Combat is not a valid member of ReplicatedStorage "ReplicatedStorage"  -  Server - M2:1
  00:35:16.433  Stack Begin  -  Studio
  00:35:16.433  Script 'Workspace.Model.Nichirins.Katana.Combat.M2', Line 1  -  Studio - M2:1
  00:35:16.434  Stack End  -  Studio
  00:35:16.435  Combat is not a valid member of ReplicatedStorage "ReplicatedStorage"  -  Server - Script:2
  00:35:16.435  Stack Begin  -  Studio
  00:35:16.436  Script 'Workspace.Model.Nichirins.Katana.Combat.RemoteEvent.Script', Line 2  -  Studio - Script:2
  00:35:16.436  Stack End  -  Studio
  00:35:16.442  StandAppearParticles is not a valid member of ReplicatedStorage "ReplicatedStorage"  -  Server - StandAppearParticles:1
  00:35:16.442  Stack Begin  -  Studio
  00:35:16.442  Script 'Workspace.Stand summon particle & summon animation.StandAppearParticles', Line 1  -  Studio - StandAppearParticles:1
  00:35:16.443  Stack End  -  Studio
  00:35:16.449  Combat is not a valid member of ReplicatedStorage "ReplicatedStorage"  -  Server - M2:1
  00:35:16.450  Stack Begin  -  Studio
  00:35:16.450  Script 'Workspace.Model.WaterSlayer.Katana.Combat.M2', Line 1  -  Studio - M2:1
  00:35:16.450  Stack End  -  Studio
  00:35:16.453  ServerScriptService.EntitySpawner:4: attempt to index nil with 'createEnemy'  -  Server - EntitySpawner:4
  00:35:16.453  Stack Begin  -  Studio
  00:35:16.453  Script 'ServerScriptService.EntitySpawner', Line 4  -  Studio - EntitySpawner:4
  00:35:16.454  Stack End  -  Studio
  00:35:16.455  Workspace.Model.Urokodaki.ClickPart.QuestTake:8: Expected 'end' (to close 'function' at line 1), got <eof>; did you forget to close 'then' at line 3?  -  Studio - QuestTake:8
  00:35:16.456  Combat is not a valid member of ReplicatedStorage "ReplicatedStorage"  -  Server - Script:2
  00:35:16.456  Stack Begin  -  Studio
  00:35:16.457  Script 'Workspace.Model.WaterSlayer.Katana.Combat.RemoteEvent.Script', Line 2  -  Studio - Script:2
  00:35:16.457  Stack End  -  Studio
  00:35:16.468  Ragdoll script activated  -  Server - Ragdoller:1
  00:35:16.475  Decal is not a valid member of Part "Workspace.StarterCharacter.Head"  -  Server - Script:4
  00:35:16.475  Stack Begin  -  Studio
  00:35:16.475  Script 'Workspace.StarterCharacter.Head.Script', Line 4  -  Studio - Script:4
  00:35:16.475  Stack End  -  Studio
  00:35:16.476  Workspace.Kizuki Pose Set.READ ME:1: Incomplete statement: expected assignment or a function call  -  Studio - READ ME:1
  00:35:16.478  Ragdoll script activated  -  Server - Ragdoller:1
  00:35:19.349  Ro-Defender has removed a total of 0 viruses and junk items from your games!  -  Server
  00:35:21.545  Infinite yield possible on 'ReplicatedStorage:WaitForChild("WaterBreathEffects")'  -  Studio
  00:35:21.545  Stack Begin  -  Studio
  00:35:21.545  Script 'Workspace.Model.Breath of Water.BreathofWater', Line 7  -  Studio - BreathofWater:7
  00:35:21.545  Stack End  -  Studio
  00:35:29.846  HumanoidRootPart is not a valid member of Model "Workspace.Model.WaterSlayer"  -  Server - FollowAndAttack:59
  00:35:29.846  Stack Begin  -  Studio
  00:35:29.846  Script 'Workspace.Model.WaterSlayer.FollowAndAttack', Line 59 - function findTargets  -  Studio - FollowAndAttack:59
  00:35:29.847  Script 'Workspace.Model.WaterSlayer.FollowAndAttack', Line 196 - function onHeartbeat  -  Studio - FollowAndAttack:196
  00:35:29.847  Script 'Workspace.Model.WaterSlayer.FollowAndAttack', Line 203  -  Studio - FollowAndAttack:203
  00:35:29.847  Stack End  -  Studio
  00:35:30.871  Hair2 is not a valid member of Model "Workspace.Model.WaterSlayer"  -  Server - Respawn:6
  00:35:30.871  Stack Begin  -  Studio
  00:35:30.871  Script 'Workspace.Model.WaterSlayer.Respawn', Line 6  -  Studio - Respawn:6
  00:35:30.871  Stack End  -  Studio
1 Like

Try printing the enemies parent. Maybe another script is changing it.

1 Like

I deleted all the other script but it still doesn’t work

1 Like

Try opening the find all / replace all menu in the view tab. Then type in:

.Parent =

Try going threw all results and find if any are related to the zombie’s parent.

1 Like

These are the only two .Parent = i found

Enemy.Parent = Enemies
PlayerBase.Touched:Connect(function(Inst)
	if Inst.Parent == Enemies then 
		print(Inst.Name)
	end
end)

Is enemies a variable? (Charrrrrr)

yes its also the name of the Folder in Workspace

1 Like

Check if Enemies is not nil. I would do so by printing it:

print(Enemies)

where do I put it under local Enemies = Map.Enemies?

1 Like

Doesn’t matter as long as the script knows what it is. If it uses another variable to locate it, print it and repeat it until you can find nil. If you can’t, then try re writing it, I may be missing something however.

here is what the problem might be:

02:24:54.367  ServerScriptService.EntitySpawner:4: attempt to index nil with 'createEnemy'  -  Server - EntitySpawner:4
  02:24:54.368  Script 'ServerScriptService.EntitySpawner', Line 4  -  Studio - EntitySpawner:4

here is line 4:

local Enemy = EnemyHandler.EnemyHandler.createEnemy({

it looks normal to me though

@captan40000 how cant it find createEnemy when local Enemy = EnemyHandler.createEnemy()?

1 Like

Can you elaborate? I don’t understand.

thanks for your help I deleted this part of the script and it works perfectly fine idk was the code incomplete?

for  i = 1, 10 do 
	local Enemy = EnemyHandler.EnemyHandler.createEnemy({
		Damage = 10 
	})
end

robloxapp-20220213-0247253.wmv (2.3 MB)

2 Likes

Very good to know. Sometimes just re writing thing fixies it because you do it differently and probably fixed a forgotten part.