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

I tried doing a test and that didn’t work this is what I did tho.

Client

local testc = nil
RegisterNetEvent(‘testc’)
AddEventHandler(‘testc’, function(test)
testc = test
print(testc)
end)

Server

local test = false
local barrel = xPlayer.getInventoryItem(‘barrel’).count,
if barrel >= 1 then
test = true
TriggerClientEvent(“testc”, source, test)
elseif barrel == 0 then
test = false
TriggerClientEvent(“testc”, source, test)
end
end)

Don’t make another topic with the same post from yesterday. SPAMMING the forums is NOT gonna solve your problems any faster.

Created a different post cause it’s a different script Plus idk how this could even be considered spam why don’t you look at the server bazar where post get bumped every hour

Look at your activity on your profile…

Looks like the same thing to me.

same end result but its for a different script but whatever

Its for a different script but its using the same method as the other one…

Client:

local testc = nil
RegisterNetEvent("testi")
AddEventHandler("testi", function(testit)
    testc = testit
    print(testc)
end)

Server

local barrel = xPlayer.getInventoryItem('barrel').count
if barrel >= 1 then
    local test = true
    TriggerClientEvent("testi", source, test)
elseif barrel == 0 then
    local test = false
    TriggerClientEvent("testi", source, test)
end

ill try that
should i make test on the server testit not test?

Yeah try not name the variable the same as the argument…

Hmm nope still wont print testc

client

local testc = nil
RegisterNetEvent(“testi”)
AddEventHandler(“testi”, function(testit)
testc = testit
print(testc)
end)

server

RegisterServerEvent(‘t’)
AddEventHandler(‘t’, function()
local xPlayer = ESX.GetPlayerFromId(source)
local barrel = xPlayer.getInventoryItem(‘barrel’).count
if barrel >= 1 then
local testit = true
TriggerClientEvent(“testi”, source, testit)
elseif barrel == 0 then
local testit = false
TriggerClientEvent(“testi”, source, testit)
end
end)

How you call the server event?

I see no error… so

with a esx menu

if data.current.value == ‘p’ then
TriggerServerEvent(“t”)
end

Make a print on the server event, to see if it gets called.

Also try:

TriggerClientEvent ("testi", source, 0) -- To set it false
TriggerClientEvent ("testi", source, 1) -- To set it true

so do a print(testit) when i go to do the client event?

make a print before the TriggerClientEvent

yep that printed the false

So…
Instead of source do this:
TriggerClientEvent(“testi”, xPlayer.source, testit)

nope still only prints the testit print not the testc :frowning:

Idk, but you can also try this…
TriggerClientEvent(“testi”, -1 ,source, testit)

On client:

local testc = nil
RegisterNetEvent(“testi”)
AddEventHandler(“testi”, function(id, testit)
local myId = PlayerId()
local pid = GetPlayerFromServerId(id)
if pid == myId then
testc = testit
print(testc)
end
end)

The way i explain you, should work, if you want specific help, PM me an pass me the resource, cause i think you might have an error on the resource, that make the client event cant be called

Alright ill pm you know cause this is super annoying :smiley: