I’m going to use InsertService to load in a load of the assets for my game, including server scripts, but I can’t figure out how to give clients localscripts from the server once they’ve loaded in.
Is this even possible, or will I have to have all localscripts on the client at all times rather than load them in using InsertService from the server?
Copy your LocalScript from the server to the Clients PlayerGui?
I’ve done it by throwing LocalScripts into the Backpack
I guess this and @Madpoint83’s solutions will work - it’s kind of annoying how the server can’t access PlayerScripts (can’t think of why not) but I’ll do that. I guess from there, I could still just move the script to the actual PlayerScripts if I wanted.
Thanks!
I forgot: You can also put LocalScripts in the player’s Character model and they will run. But it will be destroyed when the character dies, so it’s only useful if your script is only & directly affecting the character model.
You mean StarterCharacterScripts? Also @Lightlimn, you can just put them in a folder if you really want but I do not see any valid reasons to be manipulating where other scripts go (unless when necessarily placing inside characters for like vehicle controls or etc) when you can just handle things in the script itself when warrented.
I meant parenting them directly to the Character model, which is what StarterCharacterScripts does. But OP wants to do it during runtime.
Yeah, I don’t really need to, so I probably won’t. It’s just a bit annoying how there’s a StarterPlayerScripts folder yet the server can’t put stuff in it, but can put scripts in the StarterGui folder. It doesn’t matter at all lol, just feels neater I guess.
You can try moving the specific local scripts to these locations: Backpack, StarterGui, StarterPlayerScripts!
Out of curiosity, what’s your case for loading your scripts through the InsertService? Normally I’d have everything ready at run time, with exception to private modules which I rarely use or authorize in my places nowadays.
Multiple places in a universe/game. Most need the same scripts, both server and client and adding it from InsertService means I can just update a model rather than go through each place in my game and update each one.
Sounds like you’re going to have a lot of fun with packages and universe services when they come out.
LocalScripts in replicatedfirst run locally.
To be honest I have no idea why localscripts cant be placed and run from anywhere now that filteringenabled is the only data model.
There are many amazing tricks you can do by exploiting doing things only on the client.
A technique I am using is I am monitoring the entire client workspace tree with a localscript connected to decendantadded, and use it to hook up localscript behaviors on client objects.
Eg: on the server my monsters are single parts for collision and ai, but on the client they have complex models and logic for animation that get attached locally only.
Yeah, I saw that and it’s pretty good. Not sure if I’ll use them until they add auto-updating though.
Also @robloxchickenrocket I am doing the same for players and NPCs in my game too.