Why are scripts in StarterPlayerScripts running?

  1. I’m trying to make a system where it requires all modules and adds them to a global table, but for some it seems like module scripts in StarterPlayerScripts are being required.

  2. I’ve tried looking on DevForum but I cant find anything that works for my case

Heres some pictures(this explains why its a very bad problem):
adding scripts to global table:


mouse connections in a module that is required:
image
what it prints:
image

.__call method for global table:

methods = {
	__call = function(tab, index, value)
		if threads then threads[coroutine.running()] = coroutine.running() end
		global[index] = value
		return value
	end
}

There’s usually some pretty critical differences between what the server can see and what the client can see. Depending on where you’re running your script, v’s properties could be very different from what you expect. As such, your game will think the conditions are always true and require every script. This is purely speculatory, though, as I don’t know what v is. I’d add some logpoints to figure out what v is and go from there.

Another conflict point I see is the global keyword you’re using. I couldn’t find anything about Luau having such a keyword, so it might be doing stuff you’re not expecting. If you want to declare a global table, you can just type a variable name without the local keyword to declare it implicitly. Then add the required module scripts to that table. That is, to declare a global table named “foo”, you only need to type foo = {} and add the required module script tables to it via table.insert. This page describes a more advanced, but much safer way of making global variables.

1 Like

Global is a module I created I just didn’t show it in the picture(mb), the script is being ran on the client and v will always be a module script

1 Like

Nevermind, the problem was because it would still access modules in starterplayerScripts because they are tagged “ClientGlobal” and still exist alongside the modules inside of PlayerScripts. I fixed it by parenting all the module scripts to global then just running a loop that requires all of the modules parented to global and puts them into the global table.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.