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