Data from Client to Server

Hi everyone, quick question as I can’t seem to find it. Is this still a thing? If so, can somebody explain it to me and will the code below work, I’ve been using various client and server events to retrieve data and it’s a mess when you have lots of code.

I’ve put this in my server-side

RegisterCommand("testa", function(source, args, rawCommand)
    TriggerClientEvent("testEvent", -1 , {
        wow = function(str)
            print(str)
        end
    })
end)

And in my client-side:

RegisterNetEvent("testEvent")
AddEventHandler("testEvent", function(fnc)
    print("test")
    fnc.wow("yeah yeah yeah")
end)

This is just to test this theory and I don’t even get the “test” in the console, only an error:

If this is still a working thing, it would great as I could use it to reduce the abundance of events I use just to get a message from a HTTP request. Either I’m really stupid and I’m doing something very wrong or it doesn’t exist anymore; I wouldn’t be surprised if it didn’t considering the post was made in Dec 2017.

If anybody has any ideas on what to do here, that’d be great!

TIA
James

Bump, still wondering…

Hey there,

so this is a bit strange seeing as everything is looking ok.
As far as sending data from the client to the server (and vice versa) this is the method I use.

serverside

RegisterNetEvent('sv:recievedata')
AddEventHandler('sv:recievedata', function(data)
  print(data) -- do whatever with data, in this case print it out
end)

AddEventHandler('sv:senddata', function(targetClient, data)
  TriggerClientEvent('cl:recievedata', targetClient, data)
end)

-- test this code: prints the below string in the clients' console
local string = "I'm the server, not Gosu"
TriggerEvent('sv:senddata',  string)

clientside

RegisterNetEvent('cl:recievedata')
AddEventHandler('cl:recievedata', function(data)
  print(data)
end)

AddEventHandler('cl:senddata', function(data)
  TriggerServerEvent('sv:recievedata', data)
end)

-- test this code: prints the below string in the server console
local string = "Hi I'm Gosu"
TriggerEvent('cl:senddata', string) 

This is what will work.

As far as your code:

Try printing out as much as possible, e.g. this:

Serverside

RegisterCommand("testa", function(source, args, rawCommand)
  local List = {
    wow = function(str)
      print(str)
    end
  }
  print(List) -- should give some hex code with "table" in name
  print(List.wow) -- should print some function hex code
  TriggerClientEvent("testEvent", -1, List)
end)

Clientside

RegisterNetEvent("testEvent")
AddEventHandler("testEvent", function(List)
  print('Event 
  print(List) -- should give some hex code with "table" in name
  print(List.wow) -- should print some function hex code
  List.wow("yeah yeah yeah")
end)

Check whether everything prints what it is supposed to do or returns nil. That would be the point where the issue happens.

1 Like

Thanks for your reply, I added the changes to client-side and server-side and it prints everything it’s supposed to, except for what’s supposed to come out of the function.

image

It shows the hex for both the table and function however, it doesn’t print the string that was passed in List.wow(). Is there maybe a different way to call the method? I’m not too sure.

Maybe try:

List:wow("whatever")

or

List["wow"]("whatever")

Otherwise I am out of ideas but I do believe that @ChieF-TroN was able to get this to work. Might remember wrong though, it’s been like 8 months :smiley:

1 Like

Yeah, I’m out of ideas to be honest. I tried the top one already, and just now tried the bottom one but I’ve got nothing. I really appreciate you trying to help me though! We’ll just have to see if anybody else has any ideas…

Thinking of returning to this project, quick bump to see if anybody has any ideas?

You cannot access a role created on the server side through the client side. This is because the function is stored on the server’s computer or memory region, that is, the client cannot access it. As you can see in the print that appeared on the console, it showed the memory address where that function is stored on the server.

For you to be able to do what you want, you have to use something similar to what VRP uses.

Something like that:

1 Like

Alrighty, I’ll try and mock up something that could work. I didn’t realise it worked that way, but now that I think of it, I can’t really think of any other way it would. Thanks for your help.

1 Like