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

W002: Global 'loadfile' is deprecated ?

This is my script:

file = loadfile("C:/local.lua")
file()

I coped this from the roblox Function dump/Functions specific to Roblox and only changed the file to load but when I run the script I get an error "An error occured" and an error line under the word 'loadfile' in the script editor - error: W002: Global 'loadfile' is deprecated. Is there a way to fix this?

1 comment

0

Nope. It's at a higher context for a reason.

1 answer

✓ Accepted answer

loadfile() was replaced by require() and its not used like that you need to give it a directory like script.Parent or game.ServerScriptService.Script here is how you would use the new one #In ModuleScript which is in the same directory of the regular script named "ModuleScript"

function module()
	print("Congratulations you used this correctly")
end
return module

#In regular script located in the same directory of the module script

local file=require(script.Parent.ModuleScript)
file()

2 comments

0

What was wrong about my statement?

0

I was asking about loading a file that is in my system drive not about module scripts, but I did not downvote your reply.

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