Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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.

1 comment

0

sigh.. how did I miss that? lmao thanks a lot dude

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

This discussion is preserved as it was. New answers, comments, and votes are closed.