Ad
Log in to vote
0

Weird error pops up every time I try to run my code. Can someone tell me whats wrong with my code?

Asked by 15 days ago
Edited 15 days ago

I am trying to make a tower defense game. I write some code to make the zombies spawn into the map but for some reason it says " ServerScriptService.Main.mob:2: Expected ')' (to close '(' at line 1), got <eof>" and " Attempted to call require with invalid argument(s)".... I do not know what it means and it's the only thing preventing my code from working. Please help.

Here's the code:

local mob = require(script.mob)
local map = workspace.Thickboard
mob.Spawn("Zombie",map )

And some more code in a second script.

local ServerStorage = game:GetService("ServerStorage")
local mob = {}

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)
return mob

1 answer

Log in to vote
0
Answered by 15 days ago

I believe you just didn't have enough ends in your module script. The error saying that you had invalid arguments was just because your module script was written incorrectly. Here should be a fixed script:

local ServerStorage = game:GetService("ServerStorage")
local mob = {}

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

return mob

Any time you see "eof" in one of your error outputs it means that you either have too many ends or not enough. If you have any questions leave a comment :)

0
Thanks man. Awesome. PLAINSTER10 4 — 14d
Ad

Answer this question