You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? The script to work
What is the issue? Module code did not return exactly one value
What solutions have you tried so far? I’ve rewritten the code multiple times
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
Main code with the error
local mob = require(script.Mob)
local map = workspace.Grassland
for i=1, 3 do
mob.Spawn("Zombie", map)
task.wait(1)
end
Module
local ServerStorage = game:GetService("ServerStorage")
local mob = {}
function mob.Move(mob, map)
local humanoid = mob:WaitForChild("Humanoid")
local waypoints = map.Waypoints
for waypoint=1, #waypoints:GetChildren() do
humanoid:MoveTo(waypoints[waypoint].Position)
humanoid.MoveToFinished:Wait()
end
end
function mob.Spawn(name, map)
local mobExists = ServerStorage.Mobs:FindFirstChild(name)
if mobExists then
local newMob = mobExists:Clone()
newMob.HumanoidRootPart.CFrame = map.Start.CFrame
newMob.Parent = workspace
else
warn("Requested mob does not exist:", name)
end
end
Hi! I believe the issue is that you perhaps forgot to insert a return statement for you function, so when you do mob.Spawn, I suspect it returns no value, since you do not have a return piece. To fix this, at the end of mob.Spawn do the following:
local ServerStorage = game:GetService("ServerStorage")
local mob = {}
function mob.Move(mob, map)
local humanoid = mob:WaitForChild("Humanoid")
local waypoints = map.Waypoints
for waypoint=1, #waypoints:GetChildren() do
humanoid:MoveTo(waypoints[waypoint].Position)
humanoid.MoveToFinished:Wait()
end
end
function mob.Spawn(name, map)
local mobExists = ServerStorage.Mobs:FindFirstChild(name)
if mobExists then
local newMob = mobExists:Clone()
newMob.HumanoidRootPart.CFrame = map.Start.CFrame
newMob.Parent = workspace
else
warn("Requested mob does not exist:", name)
end
--return something
return mobExists -- This is an example of returning exactly one value
end
In a more technical explaination (feel free to ignore this), it expects you to return a Set S whose cardinality is 1, but you return nothing or the empty set, whose cardinality is 0. I hope this helps!