[help] Noob question "how can i pass a var from server to client"


#1

im not sure how i can pass a true or false from the server to the client.

Thanks :smiley:


[Solved] How can i pass a true or false from server to client?
#2

Use client and server events.


#3

could you give me an example:D


#4

When i get home i will show you. If you search up my k9 i do some of server to client.


#5

Alright np great script btw
i dont understand what to look for or i wouldxD


#6

Any events on the server called TriggerClientEvent is passing data on the k9.


#7

ok ill look

20Characters


#8
TriggerClientEvent("K9:SearchVehicle", src, K9Config.Items)

Src is the client to target and K9Config.Items is the table im passing from the config.


#9

so just change the src to whatever my var is then set like new var = that var? confused


#10

Src is a players id. Change src to source and pass your true / false over my k9config.items.


#11

ok so like
cause im trying to see if they have the items from the inventory so i made a event that checks it the changes has to true or false

TriggerClientEvent(“esx_crafting:giveWeapon”, source, has)


#12

Do you know how to register a client event.


#13

edited that part up there so like that?


#14

Yeah the K9:SearchVehicle is a register net event on the client.


#15

Do i need the source part to just pass the true or false?


#16

So something like this?

Server.lua

RegisterServerEvent(‘esx_crafting:check’)
AddEventHandler(‘esx_crafting:check’, function()
local xPlayer = ESX.GetPlayerFromId(source)
local BarrelQuantity = xPlayer.getInventoryItem(‘barrel_pooch’).count
local FrameQuantity = xPlayer.getInventoryItem(‘frame’).count
local StockQuantity = xPlayer.getInventoryItem(‘stock’).count

if BarrelQuantity >= 1 and FrameQuantity >= 1 and StockQuantity >= 1 and not BarrelQuantity == nil and not FrameQuantity == nil and not StockQuantity == nil then
	has = true
	TriggerClientEvent("esx_crafting:pass", has)
else
	has = false
end

end)

Client

RegisterNetEvent(‘esx_crafting:pass’)
AddEventHandler(‘esx_crafting:pass’, function(has)
hasS = has
end)


#17

TriggerClientEvent(“event”, HAS_TO_HAVE_AN_ID, has)


#18

so i do have to put source there?


#19

I added source there still didn’t work :frowning:


#20

ah. ok. source only exists when a server event is called from the client. You need to put your server id as where source is.