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()
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()
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.
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.
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.
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.