So that I may use them in any script in the place, including LocalScripts and server Scripts.
I made a global function using _G in a LocalScript, but when I tried to call it on a server Script, it failed.
So that I may use them in any script in the place, including LocalScripts and server Scripts.
I made a global function using _G in a LocalScript, but when I tried to call it on a server Script, it failed.
(I would post this in a comment if I had 10+ reputation) I'm fairly sure you cannot specify a global functions (and global variables) in a localscript. Try putting it into a normal one:
_G["hellomynameisfunction"]=function()
print("WHOA MAN I JUST DID SOMETHING")
end
_G.hellomynameisfunction()
Very simple,
_G["FunctionName"] = function(argument1,argument2)
print("Code Goes Here Yada Yada")
end
Then to call it, You use...
print("GUYS IMA DO SOMETHING GLOBAL!")
_G.FunctionName("Somethingthere","somethinghere")
print("I Did It")
You could also do something like,
_G["IsOwnerHere"] = function()
is = false
for i,v in pairs(game.Players:children() do
if v.userId == game.CreatorId then
is = true
end
end
return is
end
Then if your in the game
B = _G.IsOwnerHere()
--B = true
This discussion is preserved as it was. New answers, comments, and votes are closed.
5 comments
If this helped, An Upvote would be greatly appriciated.
That is exactly what I did. I put code like the first snippet into a LocalScript then attempted something like the second snippet in a server script, and it did not work.
Hmm
The only issue I could imagine you having, is an error in the function or code. Post the code in your q
As far as I am aware, global functions defined in LocalScript's cannot be called in a Server Script, but the opposite does work.