Jump to content

[C#/JS] Getting SharedData on Client


Recommended Posts

Hi, I'm having issues getting SharedData that is set on the Server (C#) on the client (JS) with getVariable. I currently get "undefined" on the client. I have looked it up many times and now I'm here asking this question. 

The code below outlines the following: The client connects to the server and at this time, its setSharedData. After the command testData is used, it triggers a client side event that fires and prints out the sharedData value. 

Here is my code: 

Server Side (C#):

public void OnPlayerConnected(Client player)
  player.SetSharedData("test", "test");

public void CMD_testData(Client client)
  client.SendChatMessage("Testing Data on Client!");

Client Side (JS):

function showData()
	let vartest = mp.players.local.getVariable('test');
	mp.gui.chat.push("DATA TEST: "+vartest);


Any help anyone can give is appreciated. Thank you.

Link to comment
Share on other sites

After further analysis, I have found out that the C# function "setSharedData" isn't putting data into the key that I specified. I tested that by outputting it on the server and also using "hasSharedData" with that returning false. I was scripting the server side initially with JS but moved the JS files out of the directory. Am I missing anything?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...