Hello! I tryed to make a script with function UI.SetCursorVisible(true), but it give me error that server script tryed to use client-only namespace. I tryed again, but create a ClientContext in World and make my script his child. But it give me the same error again. Can you suggest me what i'm doing wrong?
What you have done should work, I tested this:
Create a new project.
In the hierarchy right click: Create Network Context - New Client Context .
Right click on the newly created ClientContext folder and Create - Create Scripts & Gameplay Assets - Create New Script, call it ClientTest, edit the script and add the single line:
UI.SetCursorVisible(true)
Save the script and press play, you should be able to see your cursor on the screen.
Did you leave a copy of your script outside of the ClientContext folder?
No, i don't leave copy of my script outside of the ClientContext folder.
Did you try doing what I tried above with a new project? As doing exactly that works for me.
If it does not work for you then reboot your PC and try again (very occasionally I have had a problem with Core that is not cleared by simply closing and restarting the program).
But wait he give me error but do what i want (cursor visible)
What is the full error?
Error running Lua task: [25439CB480AC23CE] ButtonScript:2: Server script attempted to access a client-only field in a namespace. Field: UI.SetCursorVisible
So somewhere you have an instance of ButtonScript outside of a Client Context. Are you spawning a template at run time that contains this? I'm assuming that if you just do my simple new project test it works OK?
No, this is only ButtonScript for now in my project.
Maybe, i should Restart my Notebook?
Are you also sure that you do not have a ServerContext folder further above your Client Context folder? If not then restart. Then do my simple test.
No, it not worked. When i tryed again, it still error that do nothing. I think that this is Core bug and try to get rid of this error make no sense.
Did you do the simple test? I think it is very unlikely to be a Core bug.
Ok, i do this test right now.
Yes, i did, and error don't appeared.
OK. Start with this test project and slowly add in the parts of your real project until you discover the cause of the error.
Phew! It's good that i solved this problem without recreating my game in test project. What did i do?
I deleted all standing copyes of ButtonScript and replace them with new script that does that.
Execute script logic when forms are loaded.
Use onLoad Client Scripts to manipulate a form's appearance or content.
For example, setting field or form-level messages based on the presence of a value.
Use onLoad Client Scripts sparingly as they impact form load times.