Simple error that I can't understand

Hi guys. The script cannot find “Zombie1” in Replicated Store. How to fix. Here is the script

local spawnPart = script.Parent
local spawnDistance = 50

local function checkPlayerDistance()
	while true do
		local players = game.Players:GetPlayers()

		for _, player in pairs(players) do
			local character = player.Character
			if character then
				local characterPosition = character.PrimaryPart.Position
				local partPosition = spawnPart.Position
				local distance = (characterPosition - partPosition).Magnitude

				if distance <= spawnDistance then
					print("Игрок близко. Спавн зомби.")
					local zombie = game.ReplicatedStorage.Zombie1:Clone()
				  zombie.Parent = game.Workspace
			      zombie:SetPrimaryPartCFrame(CFrame.new(spawnPart.Position))
				else
					print("Игрок далеко")
                   local zombie = game.Workspace:FindFirstChild("Zombie1")
				   if zombie then
				   zombie:Destroy()
				   end
				end
			end
		end

		wait(1)  
	end
end
checkPlayerDistance()

image
image

Try using :WaitForChid

local spawnPart = script.Parent
local spawnDistance = 50

local function checkPlayerDistance()
	while true do
		local players = game.Players:GetPlayers()

		for _, player in pairs(players) do
			local character = player.Character
			if character then
				local characterPosition = character.PrimaryPart.Position
				local partPosition = spawnPart.Position
				local distance = (characterPosition - partPosition).Magnitude

				if distance <= spawnDistance then
					print("Игрок близко. Спавн зомби.")
					local zombie = game.ReplicatedStorage:WaitForChild("Zombie1"):Clone()
					zombie.Parent = game.Workspace
					zombie:SetPrimaryPartCFrame(CFrame.new(spawnPart.Position))
				else
					print("Игрок далеко")
					local zombie = game.Workspace:FindFirstChild("Zombie1")
					if zombie then
						zombie:Destroy()
					end
				end
			end
		end

		wait(1)  
	end
end
checkPlayerDistance()
1 Like

Infinite yield possible on 'ReplicatedStorage:WaitForChild(“Zombie1”)

When you hit play in studio, do you see Zombie1 in ReplicatedStorage? Also, can you try copy and pasting the object name into the file to double check that it doesn’t have any hidden characters or whitespace.


Yes. This is all I tried. But nothing helped me. ctrl c, ctrl v did it too

1 Like

You should use

game:GetService("ReplicatedStorage")

Some game services are named “Instance”, not their actual service name - Feature Requests / Engine Features - Developer Forum | Roblox

Is there any major benefit in using :GetService() on services such as ReplicatedStorage, ServerStorage, Players, and other containers? - Help and Feedback / Scripting Support - Developer Forum | Roblox

1 Like

Hi it’s me again, anyways, you could do

repeat task.wait() until game.ReplicatedStorage.Zombie1 ~= nil

And another way which I sometimes use… :WaitForChild(item, 30)

ANNDD most guaranteed to work:

Another way would be making an object value instance which is parented to the script and set it’s value to the Zombie1 model via explorer and then get the model via the value inside the script.

1 Like

Sorry, but it’s difficult for me to depict a script with such properties. How to do it

Very unusual. Could you share a place file?

The only other thing I’d suggest is hitting this button while playing to check that the server can see Zombie1 in ReplicatedStorage as well.
image

I will send you a picture in a bit, give me a minute to get on PC.

1 Like

Sorry, but there are a lot of different objects that can interfere with you and confuse you. My game is 95% ready and I encountered such a stupid problem.

I understand that you may feel unsafe sharing your project. There is only so much we can do with the information given.

Please try the soln I provided and just see if it makes a difference.

If you make a new placefile with just the zombie in replicated storage and the spawning system, does it still have this issue?

1st Idea

view of explorer
image

properties of the object value
image

inside the script
image

2nd idea
make a variable (local … = …) referencing the zombie1 model OUTSIDE the while loop, it may be the cause since when I did my zombie spawner I did that and there we’re no issues.

Notice: I realized the little symbol I added by mistake in the 3rd image, ignore that.

1 Like

I tried it. It’s a pity that there was no result.
image
Is this correct?

That is correct. Did you alter the line to not include “game.” before the reference to ReplicatedStorage variable?

Okay, wait a minute. 12121211121212

image

local zombie = ReplicatedStorage:WaitForChild("Zombie1"):Clone()

or

local zombie = game:GetService("ReplicatedStorage"):WaitForChild("Zombie1"):Clone()
1 Like