Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Workspace.resourcespawner1:7: attempt to call global Workspace (a userdata value) help?

Asked by
pwnd64 106
8 years ago

I'm trying to make something respawn after it is destroyed (should be easy) but I keep getting the error in the title. I'm not sure how to make it go away.

Here is the code -

while true do
wait(.1)
if not game.Workspace:FindFirstChild("resource") then
print 'no resource'
wait(2)
game.Lighting.resource:Clone().Parent = game.Workspace
'spawned resource'
end
end

2 answers

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
8 years ago

You forgot print on line 7. Lua is interpreting the code as

blah.Parent = workspace("spawned resource")

-- a function call on workspace -- which is obviously not what you meant.


This is why it's bad that Lua made parenthesis optional around calling. Relatedly, you should not omit the parenthesis when calling.

0
sigh.. how did I miss that? lmao thanks a lot dude pwnd64 106 — 8y
Ad
Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
8 years ago

Function calls ignore whitespaces. So doing this still works;

function a()
end

a
''

Why this is relevant information is because you failed to provide the print function on line 7. Therefore, the script assumed you were calling a function 'Workspace' - But Workspace is not a function, thus the error.

while wait(.1) do
    if not game.Workspace:FindFirstChild("resource") then
        print 'no resource'
        wait(2)
        game.Lighting.resource:Clone().Parent = game.Workspace
        print 'spawned resource'
    end
end

Answer this question