Rolling Spawner Problem

I have a problem that I have asked a.i, devforum, youtube, etc. None of them could solve this, but I have tried a lot of solutions and I have found that the server invoke is not even being fired and the spawnNormalZombie() function is not being fired either. If you could help that would be greatly appreciated.

When I press summon nothing goes in the output except for print(“Loop Starting”) There are 2 module scripts inside the RollingServer script. These scripts are all inside ServerScriptService.


Here is what is inside the RollingServer script

local remotes = replicatedStore:WaitForChild("Remotes")

local selectChance = require(script:WaitForChild("SelectChance"))
local chanceList = require(script:WaitForChild("ChanceList"))

-- Function to spawn a normal zombie
local function spawnNormalZombie()--This function is currently the problem (I think)
	print("A Normal Zombie has Spawned")
	local zombie = game.Workspace.Spawner:FindFirstChild("Normal Zombie")
	if zombie then
		local newZombie = zombie:Clone()
		newZombie.Parent = game.Workspace.Spawner
		print("newZombie created and parented successfully")
	end
	print("A Normal Zombie has appeared!")
end

remotes:WaitForChild("RollFunction").OnServerInvoke = function(player)
	local resultTable = {}

	for i = 1, 7 do
		print("Loop Starting")
		local rollResult = selectChance.getRandomIndex(chanceList)
		table.insert(resultTable, rollResult)
		
		-- Check if the roll result is for spawning a normal zombie
		if rollResult == "Normal Zombie" then
			print(rollResult)
			spawnNormalZombie()
		end
	end

	return resultTable
end

If you need to know anything else feel free to ask 
(btw I am a beginner script so I might not know a lot of things you tell me sorry in advance)
1 Like

If this is the case, you’d want to check the script that invokes the server.

How would i check that? because I tried printing a function but it is for some reason not working

For further debugging, you’d want to put as many prints as possible to see where the code stops. Try something like this (show us the output so we also get a better idea of the problem you’re facing):

for i = 1, 7, 1 do
		print("Loop Starting")
		local rollResult = selectChance.getRandomIndex(chanceList)
		print(rollResult)
		table.insert(resultTable, rollResult)
		print(resultTable)

		-- Check if the roll result is for spawning a normal zombie
		if rollResult == "Normal Zombie" then
			print(rollResult)
			spawnNormalZombie()
		else
			print("not 'Normal Zombie'")
		end
	end

You said whenever you press on Summon it fires the ‘remotes:WaitForChild("RollFunction").OnServerInvoke’ remote, so check the LocalScript that fires it.

OHHHH I noticed something, it prints the “Normal Zombie” or “Tank Zombie” exactly 7 times, it printed it like this


So maybe I have to change the i, 7 and put the function into this script

this is what is inside the animation module if that helps

local rollResult = selectChance.getRandomIndex(chanceList)
table.insert(resultTable, rollResult)
		
if rollResult == "Normal Zombie" then
	-- code
end

It appears that rollResult is returning a table instead of a string. I also noticed that the desired string is the first value within the table. Therefore, to accurately check if the result is ‘Normal Zombie’, we need to access this first value. Modifying the condition to rollResult[1] == "Normal Zombie" should address this issue effectively:

local rollResult = selectChance.getRandomIndex(chanceList)
table.insert(resultTable, rollResult)
		
if rollResult[1] == "Normal Zombie" then
	-- code
end

Ok we are making a lot of progress. Thankyou, now there is one more problem. There is an error, Its a problem with the parenting. The spawner part gets deleted the second I press play. Here look,


the zombie model I made is in workspace but it disappears when I press play? Do you know why? I am a beginner so I dont have that much experience with these kind of errors

Ok I got rid of the spawner and parented the Zombie to the workspace instead of the spawner, it works now, it is spawning zombies but it is spawning 4 zombies every time I press the summon button. Instead of just one. It is also coming up with a lot of errors in the zombie


for i = 1, 7, 1 do 

The reason it spawn 4 zombies instead of 1 may be because you’re using a loop that runs multiple times, causing the game to make more than one zombie. Is there any specific reason why you’re using a loop? Also, could you show us all the errors you’ve encountered? It’d help a lot.

Oh yeah sorry, I fixed all of the errors. But the reason why I am using
for i = 1,7 do
is because otherwise the rolling system will look like it just is always “Normal Zombie” Here I will show you, btw I tried adding break and that solved the 4 normal zombies spawning problem. The for i = 7 thing is to play like tank zombie, fast zombie and then like then like repeat before landing on something, like sols rng. I am gonna get rid of the gui so it doesn’t matter anyways. But now the problem is it will spawn a normal zombie every time I press the summon button.


Now the only problem is it will spawn a zombie every time I press that summon button instead of choosing something and then spawning it.

So if I understand correctly, the problem you’re currently facing is that it always spawns the “Normal Zombie” instead of spawning a random zombie?

Wait I think I should try make the other models first, then I will talk back to you thx I will try it.

2 Likes

THANK YOU, IT WORKED,


I JUST NEEDED TO MAKE MORE MODELS AND THEN IT WORKED THANK YOU. THIS LITERALLY TOOK ME 2 WEEKS TO SOLVE THANK YOU. I made 4 devforum posts and your the only one who actaully made progress THANKYOU

1 Like

Ay that’s great, glad I could help!! :smile:

1 Like

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