I was making a first-person game and since I am new I searched for the multiplayer tutorial
and used this one: Real Time Multiplayer | Learn PlayCanvas
The thing is, after i completed all the necessary steps, it showed me this message in the launch tab
Uncaught TypeError: Cannot read properties of undefined (reading ‘root’)
TypeError: Cannot read properties of undefined (reading ‘root’)
Here is the link to my project-
https://playcanvas.com/project/1177020/overview/afterschool-games
Hi @totallynotapigeon and welcome!
I guess line 9 and 10 of the script with the error, should be placed inside the initialize
function of the script.
Thanks a lot! Do you mean like this?
this.socket.emit (‘initialize’);
this.player = this.app.root.findByName (‘Player’);
this.other = this.app.root.findByName (‘Other’);
var socket = this.socket;
That doesnt work.
No, it looks like you are missing some parts right now.
In the example project the initialize
function is from line 8 till line 34 of the network
script.
I copied everything correctly though, should i restart?
Sorry, what do you mean? If you copied everything correctly it should work now.
If I compare your script with the example script I see a lot of differences?
The code worked after i fixed line 9 and 10. I just forgot to hit save. Im just a bit too used to autosaving… Thanks for the help!
1 Like