I have a problem with local script ran before the server script compiled, making the player value wont be added to player object.
You can always wait for something to be added or wait for an event to occur.
Usually localscripts will run after scripts, but try using :WaitForChild()
instead of directly indexing it.
so I have a server script that will create a new IntValue instance inside player model, I did use WaitForChild in local script, but it will give back error that its infinite yield because local script ran first
There isn’t a way in a vanilla Studio setup.
You can easily make a priority system with Yucon Framework or AeroGame Framework in a matter of minutes.
Thank you, it’s work after I read the documentation, this is also really quick, I just need to copy and paste the already existing script into the preload
uh ok, is there any tip would you give me to use the plugin, it’s only work 50/50 now, the local script sometime run before the sever script again
This isn’t an error, it’s just a warning after yielding for 5 seconds to help you if you made a mistake like spelling the name wrong.
well, but if the local script compile before the server script, and the WaitForChild will keep yielding, the server script wont be able to compile, causing game to crash
I don’t think thats how it works
I don’t know, that how it is for me, 50% it will load properly and 50% it’s doesnt. I am aiming for 100% here, also because the server script is evolved around playerAdded event
You can just do :WaitForChild(thingToWait, 100) (It is not a good idea at all, there is another way to do this.)
One way, you could just try enabling the LocalScript after running a PlayerAdded connection and right after all the values have been set, index
a container accessible on the server and local to a player, and try setting the Disabled property of a LocalScript to false (initially true) - or just call require
on a ModuleScript to run code in that once it’s the right time.
Use preload functions built into there.
but one is client and one is server, how do I do it?
Why not just connect a function in the local script to a remote then fire the remote when the server script is ready?
I think the problem with the remote event is what if the player reset, the script will reset, therefore need another fire from the server, creating more problem
Then attach a function to when the player dies?
Nah, I think I don’t want to do that since the server will have to handle more, and will create more problem
https://developer.roblox.com/en-us/api-reference/event/Players/PlayerAdded I think I found the problem, the PlayerAdded event desc: “This event does not work as expected in solo mode , because the player is created before scripts that connect to PlayerAdded run. To handle this case, as well as cases in which the script is added into the game after a player enters, create an OnPlayerAdded function that you can call to handle a player’s entrance.”