Parameter miscount?

So I’m currently struggling with some events of mine, I wish to essentially send a value from the client to the server file, and be able to retrieve it at a later date. I assume I can do this through events however I seem to get an error in the console related to a parameter miscount during the “load” event.

(This values will be changed rather often so a database doesn’t really do the trick)

(Also, my apologies in advance if the code formatting is awful, I’m attempting to do this on my phone)

Client.lua

function saveValue(value)
	TriggerServerEvent('eventName:save', name, value)
end

function loadValue(name)
	TriggerServerEvent('eventName:load', name)
end

AddEventHandler('eventName:load', function(loaded_value)
	value = loaded_value
end

Server.lua

-- ----------------------------------------------------------
local value_storage = {}
-- ----------------------------------------------------------
RegisterServerEvent('eventName:load')
AddEventHandler('eventName:load', function(name)
	if (value_storage[name]) then 
		TriggerClientEvent('eventName:load', value_storage[name])
	else
		value = math.random() + math.random(1, 99)
		value_storage[name] = value
		TriggerClientEvent('eventName:load', value)
        end
end)

(The values “name” in the client file is a local variable outside the function)

Again, my apologies if any of this looks messed up, phones have come a long way but they can’t quite get it right.

When you trigger a client event, you need to specify which client to trigger it on. The proper way to do it would be

TriggerClientEvent(‘someclientevent’, clientid, arg1, arg2)

To run it on the client that triggered the server event, use source. To trigger on all clients, use -1

I believe what you are looking for is:

TriggerClientEvent('eventName:load', source, value_storage[name]) TriggerClientEvent('eventName:load', source, value)

Whenever an event is triggered on the server, there is a hidden parameter called source that just tells the script who triggered the event.

Many thanks for the fast response, however I still be facing the same issue. Here’s the updated code block:

-- ----------------------------------------------------------
local value_storage = {}
-- ----------------------------------------------------------
RegisterServerEvent('eventName:load')
AddEventHandler('eventName:load', function(name)
	if (value_storage[name]) then 
		TriggerClientEvent('eventName:load', source, value_storage[name])
	else
		value = math.random() + math.random(1, 99)
		value_storage[name] = value
		TriggerClientEvent('eventName:load', source, value)
	end
end)
-- ----------------------------------------------------------

Strangely enough this still seems to give me the parameter issues, which is awfully confusing

RegisterNetEvent("eventName:load") before you add the handler in the client code

Unfortunately I already have that also :confused:

RegisterNetEvent('eventName:load')
AddEventHandler('eventName:load', function(loaded_value)
	value = loaded_value
end)

Can you take a screenshot of the exact error, including all the lines under it that are related to that error?

So this is the best screenshot I could really get of the console, my apologies. What confused me the most is that I could really see anything which would point to any specific lines in the code.

For reference, everything in the code blocks in the previous posts contain everything to do with this script, granted that doesn’t help much when there’s no line number in the stack trace.

(Side note, I just head off for the night now, 00:20 and I have work at 8am, so you’ll have to excuse me :slight_smile: )