Is it possible to detect if a player is nearby objects?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    to have it so the zombie spawners detect where the player is and set the zombie spawns to the closest part(s) nearby the player

  2. What is the issue?
    the current zombie script grabs a table and randomizes the spawn locations. this works great in small maps however in larger maps the zombies could spawn on one side of the map while the player(s) is on the opposite site

  3. What solutions have you tried so far?
    i tried looking through the DevForum but im not finding articles related to my issue, mostly chat distance or keybinding distance stuff.

so this script is what handles the zombie spawns. its quite large so i’ll include the entire script as well as the section we’ll be focusing on

entire script

local CS = game:getService("CollectionService")




while true do
	wait(script.SpawnSpeed.Value)
	for i, v in pairs(CS:GetTagged("spawner")) do

		if game.ReplicatedStorage.Values.zombiesRemaining.Value > 0  and game.ReplicatedStorage.Values.zombiesOnScreen.Value < game.ReplicatedStorage.Values.zombieLimit.Value then
			if game.ReplicatedStorage.Values.gameInProgress.Value == true then  
				if game.ReplicatedStorage.Values.DogRound.Value == true then
					if game.ReplicatedStorage.Values.dogroom1.Value == true then
						local table = {
							game.Workspace.DogSpawns.Part1,
							game.Workspace.DogSpawns.Part2,
							game.Workspace.DogSpawns.Part3,
							game.Workspace.DogSpawns.Part4,
							game.Workspace.DogSpawns.Part5,
							game.Workspace.DogSpawns.Part6,


						}



						for i, v in ipairs(table) do

							local random = math.random(1,6)
							local doggiespawn = table[random] 
							if game.ReplicatedStorage.Values.zombiesRemaining.Value > 0  and game.ReplicatedStorage.Values.zombiesOnScreen.Value < game.ReplicatedStorage.Values.zombieLimit.Value then
								if game.ReplicatedStorage.Values.gameInProgress.Value == true then  
									doggiespawn.Loop:Play()
									doggiespawn.Glow.Enabled = true
									doggiespawn.ParticleEmitter.Enabled = true
									wait(1.4)
									v.Souls.Enabled = true
									doggiespawn.Lightning:Play()
									wait(0.4)
									doggiespawn.Glow.Enabled = false
									doggiespawn.ParticleEmitter.Enabled = false
									doggiespawn.Union.Transparency = 0
									wait(0.2)
									doggiespawn.Union.Transparency = 1
									local NPC3 = game.ReplicatedStorage.BOSS.Zombie:Clone()
									NPC3.Parent = doggiespawn.Parent
									NPC3.HumanoidRootPart.CFrame =  doggiespawn.CFrame + Vector3.new(0, 2, 0)
									CS:AddTag(NPC3, "Zombie")
									game.ReplicatedStorage.Values.zombiesRemaining.Value = game.ReplicatedStorage.Values.zombiesRemaining.Value - 1	
								end
							end
						end
						end
						if game.ReplicatedStorage.Values.dogroom2.Value == true then
							local table = {
								game.Workspace.DogSpawns.Part1,
								game.Workspace.DogSpawns.Part2,
								game.Workspace.DogSpawns.Part3,
								game.Workspace.DogSpawns.Part4,
							game.Workspace.DogSpawns.Part5,
							game.Workspace.DogSpawns.Part6,
							game.Workspace.DogSpawns.Part7,
							game.Workspace.DogSpawns.Part8,
							game.Workspace.DogSpawns.Part9,
							game.Workspace.DogSpawns.Part10,
							game.Workspace.DogSpawns.Part11,


							}



							for i, v in ipairs(table) do

								local random = math.random(1,11)
								local doggiespawn = table[random] 
								if game.ReplicatedStorage.Values.zombiesRemaining.Value > 0  and game.ReplicatedStorage.Values.zombiesOnScreen.Value < game.ReplicatedStorage.Values.zombieLimit.Value then
									if game.ReplicatedStorage.Values.gameInProgress.Value == true then  
										doggiespawn.Loop:Play()
										doggiespawn.Glow.Enabled = true
										doggiespawn.ParticleEmitter.Enabled = true
										wait(1.4)
										v.Souls.Enabled = true
										doggiespawn.Lightning:Play()
										wait(0.4)
										doggiespawn.Glow.Enabled = false
										doggiespawn.ParticleEmitter.Enabled = false
										doggiespawn.Union.Transparency = 0
										wait(0.2)
										doggiespawn.Union.Transparency = 1
										local NPC3 = game.ReplicatedStorage.BOSS.Zombie:Clone()
										NPC3.Parent = doggiespawn.Parent
										NPC3.HumanoidRootPart.CFrame =  doggiespawn.CFrame + Vector3.new(0, 2, 0)
										CS:AddTag(NPC3, "Zombie")
										game.ReplicatedStorage.Values.zombiesRemaining.Value = game.ReplicatedStorage.Values.zombiesRemaining.Value - 1	
									end
								end
							end
						
						
						end

				else
					if game.ReplicatedStorage.Values.Zomroom1.Value == true then
						local table = {
							game.Workspace.ZomSpawn.spawner1,
							game.Workspace.ZomSpawn.spawner2,
							game.Workspace.ZomSpawn.spawner3,
							game.Workspace.ZomSpawn.spawner4,
							game.Workspace.ZomSpawn.spawner5,
							game.Workspace.ZomSpawn.spawner6,
							game.Workspace.ZomSpawn.spawner7,
							game.Workspace.ZomSpawn.spawner8,
							game.Workspace.ZomSpawn.spawner9,
							game.Workspace.ZomSpawn.spawner10,
							game.Workspace.ZomSpawn.spawner11,

						}


						for i, v in ipairs(table) do
							local random = math.random(1,11)
							local ZomSpawn = table[random] 
							local sound1 = ZomSpawn:WaitForChild("sound1")
							local sound2 = ZomSpawn:WaitForChild("sound2")
							local sounds = {sound1, sound2}
							if game.ReplicatedStorage.Values.zombiesRemaining.Value > 0  and game.ReplicatedStorage.Values.zombiesOnScreen.Value < game.ReplicatedStorage.Values.zombieLimit.Value then
								if game.ReplicatedStorage.Values.gameInProgress.Value == true then  
									sounds[math.random(1, #sounds)]:Play()
									ZomSpawn.D1.Enabled = true
									ZomSpawn.D2.Enabled = true
									wait(1)
									ZomSpawn.D1.Enabled = false
									ZomSpawn.D2.Enabled = false
									local NPC = game.ServerStorage.Zombie:Clone()

									NPC.Parent = game.Workspace.Zombies
									NPC.HumanoidRootPart.CFrame = 	ZomSpawn.CFrame + Vector3.new(0, 2.5, 0)
									NPC.HumanoidRootPart.Anchored = true
									CS:AddTag(NPC, "Zombie")
									game.ReplicatedStorage.Values.zombiesRemaining.Value = game.ReplicatedStorage.Values.zombiesRemaining.Value - 1	
									wait(0.5)
								end
						end
						end
					end
					if game.ReplicatedStorage.Values.Zomroom2.Value == true then
						local table = {
							game.Workspace.ZomSpawn.spawner1,
							game.Workspace.ZomSpawn.spawner2,
							game.Workspace.ZomSpawn.spawner3,
							game.Workspace.ZomSpawn.spawner4,
							game.Workspace.ZomSpawn.spawner5,
							game.Workspace.ZomSpawn.spawner6,
							game.Workspace.ZomSpawn.spawner7,
							game.Workspace.ZomSpawn.spawner8,
							game.Workspace.ZomSpawn.spawner9,
							game.Workspace.ZomSpawn.spawner10,
							game.Workspace.ZomSpawn.spawner11,
							game.Workspace.ZomSpawn.spawner12,
							game.Workspace.ZomSpawn.spawner13,
							game.Workspace.ZomSpawn.spawner14,
							game.Workspace.ZomSpawn.spawner15,
							game.Workspace.ZomSpawn.spawner16,
							game.Workspace.ZomSpawn.spawner17,

						}


						for i, v in ipairs(table) do
							local random = math.random(1,17)
							local ZomSpawn = table[random] 
							local sound1 = ZomSpawn:WaitForChild("sound1")
							local sound2 = ZomSpawn:WaitForChild("sound2")
							local sounds = {sound1, sound2}
							if game.ReplicatedStorage.Values.zombiesRemaining.Value > 0  and game.ReplicatedStorage.Values.zombiesOnScreen.Value < game.ReplicatedStorage.Values.zombieLimit.Value then
								if game.ReplicatedStorage.Values.gameInProgress.Value == true then  
									sounds[math.random(1, #sounds)]:Play()
									ZomSpawn.D1.Enabled = true
									ZomSpawn.D2.Enabled = true
									wait(1)
									ZomSpawn.D1.Enabled = false
									ZomSpawn.D2.Enabled = false
									local NPC = game.ServerStorage.Zombie:Clone()

									NPC.Parent = game.Workspace.Zombies
									NPC.HumanoidRootPart.CFrame = 	ZomSpawn.CFrame + Vector3.new(0, 2.5, 0)
									NPC.HumanoidRootPart.Anchored = true
									CS:AddTag(NPC, "Zombie")
									game.ReplicatedStorage.Values.zombiesRemaining.Value = game.ReplicatedStorage.Values.zombiesRemaining.Value - 1	
									wait(0.5)
								end
							end
						end
					end
					if game.ReplicatedStorage.Values.Zomroom3.Value == true then
						local table = {
							game.Workspace.ZomSpawn.spawner1,
							game.Workspace.ZomSpawn.spawner2,
							game.Workspace.ZomSpawn.spawner3,
							game.Workspace.ZomSpawn.spawner4,
							game.Workspace.ZomSpawn.spawner5,
							game.Workspace.ZomSpawn.spawner6,
							game.Workspace.ZomSpawn.spawner7,
							game.Workspace.ZomSpawn.spawner8,
							game.Workspace.ZomSpawn.spawner9,
							game.Workspace.ZomSpawn.spawner10,
							game.Workspace.ZomSpawn.spawner11,
							game.Workspace.ZomSpawn.spawner12,
							game.Workspace.ZomSpawn.spawner13,
							game.Workspace.ZomSpawn.spawner14,
							game.Workspace.ZomSpawn.spawner15,
							game.Workspace.ZomSpawn.spawner16,
							game.Workspace.ZomSpawn.spawner17,
							game.Workspace.ZomSpawn.spawner18,
							game.Workspace.ZomSpawn.spawner19,

						}


						for i, v in ipairs(table) do
							local random = math.random(1,18)
							local ZomSpawn = table[random] 
							local sound1 = ZomSpawn:WaitForChild("sound1")
							local sound2 = ZomSpawn:WaitForChild("sound2")
							local sounds = {sound1, sound2}
							if game.ReplicatedStorage.Values.zombiesRemaining.Value > 0  and game.ReplicatedStorage.Values.zombiesOnScreen.Value < game.ReplicatedStorage.Values.zombieLimit.Value then
								if game.ReplicatedStorage.Values.gameInProgress.Value == true then  
									sounds[math.random(1, #sounds)]:Play()
									ZomSpawn.D1.Enabled = true
									ZomSpawn.D2.Enabled = true
									wait(1)
									ZomSpawn.D1.Enabled = false
									ZomSpawn.D2.Enabled = false
									local NPC = game.ServerStorage.Zombie:Clone()

									NPC.Parent = game.Workspace.Zombies
									NPC.HumanoidRootPart.CFrame = 	ZomSpawn.CFrame + Vector3.new(0, 2.5, 0)
									NPC.HumanoidRootPart.Anchored = true
									CS:AddTag(NPC, "Zombie")
									game.ReplicatedStorage.Values.zombiesRemaining.Value = game.ReplicatedStorage.Values.zombiesRemaining.Value - 1	
									wait(0.5)
								end
							end
						end
					end
					
					
					
					
					local table = {
						game.Workspace.ZomSpawn.spawner1,
						game.Workspace.ZomSpawn.spawner2,
						game.Workspace.ZomSpawn.spawner3,
						game.Workspace.ZomSpawn.spawner4,
						game.Workspace.ZomSpawn.spawner5,
						game.Workspace.ZomSpawn.spawner6,

					}


					for i, v in ipairs(table) do
						local random = math.random(1,6)
						local ZomSpawn = table[random] 
						local sound1 = ZomSpawn:WaitForChild("sound1")
						local sound2 = ZomSpawn:WaitForChild("sound2")
						local sounds = {sound1, sound2}
						if game.ReplicatedStorage.Values.zombiesRemaining.Value > 0  and game.ReplicatedStorage.Values.zombiesOnScreen.Value < game.ReplicatedStorage.Values.zombieLimit.Value then
							if game.ReplicatedStorage.Values.gameInProgress.Value == true then  
								sounds[math.random(1, #sounds)]:Play()
								ZomSpawn.D1.Enabled = true
								ZomSpawn.D2.Enabled = true
								wait(1)
								ZomSpawn.D1.Enabled = false
								ZomSpawn.D2.Enabled = false
								local NPC = game.ServerStorage.Zombie:Clone()
						
								NPC.Parent = game.Workspace.Zombies
								NPC.HumanoidRootPart.CFrame = 	ZomSpawn.CFrame + Vector3.new(0, 2.5, 0)
								NPC.HumanoidRootPart.Anchored = true
								CS:AddTag(NPC, "Zombie")
								game.ReplicatedStorage.Values.zombiesRemaining.Value = game.ReplicatedStorage.Values.zombiesRemaining.Value - 1	
								wait(0.5)
							end
						end
					end
				end
			end

		end

	end	
end


its large due to it checking if player has opened doors to new ‘rooms’ (areas) and adding spawn locations into the randomizer. it also checks if its on a dog round aswell as the ‘rooms’ available to spawn in.

also the tagged ‘Spawners’ is how i used to handle the spawning locations but as of yesterday im experimenting with this new spawning functionality
(previous one would have all the zombies spawn in at tagged locations of “spawn” all at once. this new way makes it randomized as well as a bit cleaner in having each location having effects/SFX and more performance friendly instead of having 30+ humanoids cloned into the map all at once)

again this works great in a small scale map, however in a big map it can cause long round times.

to make things easier lets focus on this area:

					local table = {
						game.Workspace.ZomSpawn.spawner1,
						game.Workspace.ZomSpawn.spawner2,
						game.Workspace.ZomSpawn.spawner3,
						game.Workspace.ZomSpawn.spawner4,
						game.Workspace.ZomSpawn.spawner5,
						game.Workspace.ZomSpawn.spawner6,

					}

for i, v in ipairs(table) do
						local random = math.random(1,6)
						local ZomSpawn = table[random] 
						local sound1 = ZomSpawn:WaitForChild("sound1")
						local sound2 = ZomSpawn:WaitForChild("sound2")
						local sounds = {sound1, sound2}
						if game.ReplicatedStorage.Values.zombiesRemaining.Value > 0  and game.ReplicatedStorage.Values.zombiesOnScreen.Value < game.ReplicatedStorage.Values.zombieLimit.Value then
							if game.ReplicatedStorage.Values.gameInProgress.Value == true then  
								sounds[math.random(1, #sounds)]:Play()
								ZomSpawn.D1.Enabled = true
								ZomSpawn.D2.Enabled = true
								wait(1)
								ZomSpawn.D1.Enabled = false
								ZomSpawn.D2.Enabled = false
								local NPC = game.ServerStorage.Zombie:Clone()
						
								NPC.Parent = game.Workspace.Zombies
								NPC.HumanoidRootPart.CFrame = 	ZomSpawn.CFrame + Vector3.new(0, 2.5, 0)
								NPC.HumanoidRootPart.Anchored = true
								CS:AddTag(NPC, "Zombie")
								game.ReplicatedStorage.Values.zombiesRemaining.Value = game.ReplicatedStorage.Values.zombiesRemaining.Value - 1	
								wait(0.5)

So, i am wondering if theres a way to detect if a player is nearby one of the zombies spawners and make it so the other spawners are inactive.

feedback is much appreciated, im still learning the LUA language

3 Likes

To detect nearby players, create a function that loops through each spawner and also the players. You could then find the magnitude of each player compared to the spawner.

For example:

function findClosestPlayer(spawner)
    local closestDistance -- will be used to set the closest distance of all the characters
    local closestChar -- used to set the closest character

 for i, player in pairs(game.Players:GetPlayers()) do -- loops through players
        local character= player.Character -- gets player's character
        local vector = (spawner.Position - character.HumanoidRootPart.Position) -- finds vector3 distance of spawner from character
        if not closestDistance then -- if a closest distant hasn't been set this will run
            closestDistance = vector.Magnitude -- gets magnitude of the vector3 and sets it to the closest distance
            closestChar = character-- sets the character to this variable
        else -- if there is already a closest distance this will run
            if vector.Magnitude < closestDistance then -- if the character is closest than the perviously closest character this will fire
                  closestDistance = vector.Magnitude -- sets distance to magnitude of vector3
                  closestChar = character -- sets the closest character to the current one
            end
        end

       return closestDistance, closestChar -- sends the value of the closestCharacter and closestDistance back to the script
end

-- in the main part of this script you can create a system to detect if the player is within a certain range of the spawner. I'm not sure if a while loop is how you want to achieve this but this will be the method I show you

local spawners = local table = {
						game.Workspace.ZomSpawn.spawner1,
						game.Workspace.ZomSpawn.spawner2,
						game.Workspace.ZomSpawn.spawner3,
						game.Workspace.ZomSpawn.spawner4,
						game.Workspace.ZomSpawn.spawner5,
						game.Workspace.ZomSpawn.spawner6
					}

local targetedRange = 5 -- the agro distance to activate the spawner

while wait() do
    for i, spawner in pairs(spawners) do -- loops through all the spawner so you can find the closest distance of every character rather than just one
        local  closestDistance, closestCharacter = findClosestPlayer(spawner) -- calls the function(it is a variable so you can accessthe value it returns)
        if closestDistance <= targetedRange then -- if the player is within the range of the spawner this will activate
            -- you can activate the spawner here
        end
    end
end

This is just an example for a script, so it might not work with the script you already have(I also haven’t tested this script). I’m not sure if this is what you’re trying to achieve, but if it’s not, you can just use magnitude, which is a way to find the distance between two instances.

1 Like

so i am trying to work with this and modify it, will let u know, so far the script seems to not give errors and doesnt find the closet players ( i added print statements but nothing seems to come thru except for before the function findclosetplayer

1 Like

Okay. If you are having trouble with getting the script to work, you can send my the code you are using and I can see if there are any errors.

heres what im using, im only gettin “pre spawn” and “in game”




while true do
	wait(script.SpawnSpeed.Value)
	print "pre spawn"
	
	
	if game.ReplicatedStorage.Values.zombiesRemaining.Value > 0  and game.ReplicatedStorage.Values.zombiesOnScreen.Value < game.ReplicatedStorage.Values.zombieLimit.Value then
		if game.ReplicatedStorage.Values.gameInProgress.Value == true then 
	print "ingame"
	function findClosestPlayer(spawner)
		print "first act"
					local closestDistance -- will be used to set the closest distance of all the characters
					local closestChar -- used to set the closest character

					for i, player in pairs(game.Players:GetPlayers()) do -- loops through players
						local character= player.Character -- gets player's character
						local vector = (spawner.Position - character.HumanoidRootPart.Position) -- finds vector3 distance of spawner from character
						if not closestDistance then -- if a closest distant hasn't been set this will run
							closestDistance = vector.Magnitude -- gets magnitude of the vector3 and sets it to the closest distance
							closestChar = character-- sets the character to this variable
						else -- if there is already a closest distance this will run
							if vector.Magnitude < closestDistance then -- if the character is closest than the perviously closest character this will fire
								closestDistance = vector.Magnitude -- sets distance to magnitude of vector3
								closestChar = character -- sets the closest character to the current one
							end
						end

						return closestDistance, closestChar -- sends the value of the closestCharacter and closestDistance back to the script
					end

					-- in the main part of this script you can create a system to detect if the player is within a certain range of the spawner. I'm not sure if a while loop is how you want to achieve this but this will be the method I show you

					local spawners = table {
						game.Workspace.ZomSpawn.spawner1,
						game.Workspace.ZomSpawn.spawner2,
						game.Workspace.ZomSpawn.spawner3,
						game.Workspace.ZomSpawn.spawner4,
						game.Workspace.ZomSpawn.spawner5,
						game.Workspace.ZomSpawn.spawner6
					}
print "table"
					local targetedRange = 5 -- the agro distance to activate the spawner

		while wait() do
			print"spawning"
			for i, spawner in pairs(spawners) do
						
						local  closestDistance, closestCharacter = findClosestPlayer(spawner) -- calls the function(it is a variable so you can accessthe value it returns)
						if closestDistance <= targetedRange then -- if the player is within the range of the spawner this will activate
							
							local ZomSpawn = spawner 
							local sound1 = ZomSpawn:WaitForChild("sound1")
							local sound2 = ZomSpawn:WaitForChild("sound2")
							local sounds = {sound1, sound2}  
									sounds[math.random(1, #sounds)]:Play()
									ZomSpawn.D1.Enabled = true
									ZomSpawn.D2.Enabled = true
									wait(1)
									ZomSpawn.D1.Enabled = false
									ZomSpawn.D2.Enabled = false
									local NPC = game.ServerStorage.Zombie:Clone()

									NPC.Parent = game.Workspace.Zombies
									NPC.HumanoidRootPart.CFrame = 	ZomSpawn.CFrame + Vector3.new(0, 2.5, 0)
									NPC.HumanoidRootPart.Anchored = true
									CS:AddTag(NPC, "Zombie")
									game.ReplicatedStorage.Values.zombiesRemaining.Value = game.ReplicatedStorage.Values.zombiesRemaining.Value - 1	
									wait(0.5)
							
							
							
							end
						end
					end
					end


		end
	end
end

one thing im wondering, in findclosetplayer(spawner) how is ‘spawner’ defined ? or how can i define it to be the spawn table parts

First of all, when you print make sure you have parenthesis. For example, it would be typed:

print("Hello")

Also, to define spawner, you would put inside the parenthesis what you want spawner to be. So if I put a value in the parenthesis like true, every time I say spawner in the function it would mean true. For example:

function randomFunction(spawner)
	print(spawner)
end

randomFunction(true)

Output:

true
1 Like

i see, i’ll make sure to do that with the print statements. any idea why the script isnt working or giving an error?

I have found a method with my script that works, I will try to implement it into the code you already have. Rather than using a while true do loop, it uses run service, which I think runs better. Do you want me to use your original script or the most recent one you provided 5 replies ago?

I remade the function a little bit different, but now I think it works properly. I didn’t implement this to your script because I don’t completely know what you want to happen when the spawner activates.
This is the script:

function findClosestPlayer(spawner, targetedDistance)
	local closestDistance -- will be used to set the closest distance of all the characters
	local closestChar -- used to set the closest character

	for i, player in pairs(game.Players:GetPlayers()) do -- loops through players
		local character = player.Character -- gets player's character
		local vector = (character.HumanoidRootPart.Position - spawner.Position) -- finds vector3 distance of spawner from character
		if not closestDistance then -- if a closest distant hasn't been set this will run
			closestDistance = vector.Magnitude -- gets magnitude of the vector3 and sets it to the closest distance
			closestChar = character-- sets the character to this variable
		else -- if there is already a closest distance this will run
			if vector.Magnitude < closestDistance then -- if the character is closest than the perviously closest character this will fire
				closestDistance = vector.Magnitude -- sets distance to magnitude of vector3
				closestChar = character -- sets the closest character to the current one
			end
		end
	end
	if closestDistance > targetedDistance then return end -- if the spawner is not within the targeted distance from the player, the function returns nothing(nil)

	return closestDistance, closestChar -- sends the value of the closestCharacter and closestDistance back to the script
end

game:GetService("RunService").Heartbeat:Connect(function()
	local spawners = {
		game.Workspace.ZomSpawn.spawner1,
		game.Workspace.ZomSpawn.spawner2,
		game.Workspace.ZomSpawn.spawner3,
		game.Workspace.ZomSpawn.spawner4,
		game.Workspace.ZomSpawn.spawner5,
		game.Workspace.ZomSpawn.spawner6,

	}

	for i, v in ipairs(spawners) do
		local targetedRange = 5 -- the agro distance to activate the spawner
		for i, spawner in pairs(spawners) do
			local  closestDistance, closestCharacter = findClosestPlayer(spawner, targetedRange) -- calls the function(it is a variable so you can accessthe value it returns)
			if closestDistance and closestCharacter then -- if a closest distance and closest character exists, it will activate the spawner, otherwise it won't
				-- put what you want here
			end
		end
	end
end)

Also, make sure when you add the rest of your script it is inside the runservice.heartbeat, and delete the while true do loop. You can show me how your script looks once you implement this code so I know you did it right.

sorry for late reply, its sorta working, doing some quick modifications. i tried adding in wait values for the spawning porting but its spawning hundreds of zombies at once, even with the zombie limit value being reached

Like this?

function Distance(Character:Model,Base:BasePart):boolean
	if Character:FindFirstChild("HumanoidRootPart") then
		if (Character.HumanoidRootPart.Position - Base.Position).Magnitude <= 15 then -- change?
			return true
		end
	end
end
coroutine.wrap(function()
	while task.wait() do
		for _,v:Instance? in workspace.ZomSpawn:GetChildren() do
			if v.Name:find("spawner") and v:IsA("BasePart") then
				if Distance(Character, v) then
					-- 
				end
			end
		end
	end
end)()
1 Like

i ended up getting this to work, TYSM for the help!!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.