the entire script (Gnomecode tds tutorial – script until part 3)
local PhysicsService = game:GetService("PhysicsService")
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
mob:Destroy()
end
function mob.Spawn(name, quantity, map)
local mobExists = ServerStorage.Mobs:FindFirstChild(name)
if mobExists then
for i=1, quantity do
task.wait(0.5)
local newMob = mobExists:Clone()
newMob.HumanoidRootPart.CFrame = map.Start.CFrame -- error code here
newMob.Parent = workspace.Mobs
newMob.HumanoidRootPart:SetNetworkOwner(nil)
for i, object in ipairs(newMob:GetDescendants()) do
if object:IsA("BasePart") then
PhysicsService:SetPartCollisionGroup(object, "Mob")
end
end
coroutine.wrap(mob.Move)(newMob, map)
end
else
warn("Requested mob does not exist:", name)
end
end
return mob
I will add I am not the best at scriping. I have changed the variable map to where the actual map is located, but the game will have multiple maps, so I cannot change the variable without ruining the map-system.
map is nil, you have not defined a valid object as a 3rd parameter and it is considered nil.
Reasons for that happening could be that you are sending from localscript to global and then to module while doing that, some local objects do not actually exist in the server and the variable is changed to nil.
If you could show the way it is called I be able to assist you to fixing the problem.
here is the link if you want to check the script, I have looked through the entire video and for some reason cannot find the error, and find my script the same as in the video. [New Mob Types + Animations - Tower Defense Tutorial #3 - YouTube] [New Mob Types + Animations - Tower Defense Tutorial #3 -
link:New Mob Types + Animations - Tower Defense Tutorial #3 - YouTube
could you write on that script after: local map = workspace.Grassland
Write on the next line: print(map.Name)
and check if an error occurs in console
Provide it if it does. If not it would just print out the name ‘Grassland’
If it is, try using this script in place of the original.
local PhysicsService = game:GetService("PhysicsService")
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
mob:Destroy()
end
function mob.Spawn(name, quantity, map)
local mobExists = ServerStorage.Mobs:FindFirstChild(name)
if mobExists then
for i=1, quantity do
task.wait(0.5)
local newMob = mobExists:Clone()
newMob.HumanoidRootPart.CFrame = map:WaitForChild(“Start”).CFrame -- error code here
newMob.Parent = workspace.Mobs
newMob.HumanoidRootPart:SetNetworkOwner(nil)
for i, object in ipairs(newMob:GetDescendants()) do
if object:IsA("BasePart") then
PhysicsService:SetPartCollisionGroup(object, "Mob")
end
end
coroutine.wrap(mob.Move)(newMob, map)
end
else
warn("Requested mob does not exist:", name)
end
end
return mob
If it is indeed still in Grasslands, you can try Foxy’s idea. Just straight out checking inside the map. Won’t work in the future if you have multiple maps though.