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

Module script on client and server?

I'm trying to have a module script where I can call its methods on the client and the module script itself will fire to the server and call the same methods again with server permissions. Here's what I'm trying to do for .New method

function Orb.New(Player)
	if IsClient then
		return OrbFunction:InvokeServer("New")
	else
		local self = setmetatable({}, Orb)
		--A bunch of defining variables and making parts here
		return self

It successfully returns on both the client and server side, but then when I try to call methods on the returned object on the client side, it says I'm trying to call a nil value. Did I do the creation wrong, or could the problem be elsewhere?

2 comments

0

Is this code inside the module script itself, or is it another script trying to call it?

0

This is the code inside the module script

1 answer

Okay I got it to work, but I don't exactly understand why this solution works:

if IsClient then
		local self = setmetatable(OrbFunction:InvokeServer("New"), Orb)
		return self
	else
		local self = setmetatable({}, Orb)
		--defining stuff
		return self

If anyone can explain why this works and the other one doesn't, or if this even works at all and isn't just spaghetti code, that would be nice

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