Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I'm having some problems with a zombie spawner. Can anyone help?

So, i have a value in the replicated storage, with a server script. The server script detects whenever the value is changed to true, or false. Here is my code:

local myZombie = game.ReplicatedStorage.Zombie:Clone()
local part = script.Parent
local model = script.Parent.Parent
local myHumanoidRootPart = myZombie.HumanoidRootPart
local myHumanoid = myZombie:WaitForChild("Zombie")
local inGame = game.ReplicatedStorage.GameInProgress	

if inGame.Value == true then
		myZombie:SetPrimaryPartCFrame(part.CFrame * CFrame.new(0, 5, 0))
		myZombie.Parent = model
		myHumanoid.Died:Connect(function()
		wait(7)
		local newZombie = game.ReplicatedStorage.Zombie:Clone()
		newZombie.Parent = model
		newZombie:SetPrimaryPartCFrame(part.CFrame * CFrame.new(0, 5, 0))
		if myZombie then
			myZombie:Destroy()
		end
	end)
end

inGame.Changed:Connect(function(value)
	if value == true then
		myZombie:SetPrimaryPartCFrame(part.CFrame * CFrame.new(0, 5, 0))
		myZombie.Parent = model
		myHumanoid.Died:Connect(function()
			wait(7)
			local newZombie = game.ReplicatedStorage.Zombie:Clone()
			newZombie.Parent = model
		end)
	else
		local zombie = model:FindFirstChild("Zombie")
		if zombie then
		zombie:Destroy()
		end
	end
end)

It clones whenever the value is set to true, and makes sure there is not more than one zombie in the model, and once the value is set to false, the script automatically destroys the zombie (if it is there) so that people can be in the map until a new round starts.

The error here is whenever i set the value to true, the zombies never spawn in.

I have a feeling that i am doing something wrong here that is very simple, but i don't know what. Help would be very appreciated.

1 answer

I think the problem lies in lines 22 - 23:

inGame.Changed:Connect(function(value)
if value == true then

You put value as a parameter, yet value is not defined. value is not equal to Value, so you should do it like this:

inGame.Changed:Connect(function()
if inGame.Value == true then

Hope that helped!

1 comment

0

that wasnt it

This discussion is preserved as it was. New answers, comments, and votes are closed.