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


#1

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)


#2

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


#3

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


#4

Look at your activity on your profile…

Looks like the same thing to me.


#5

same end result but its for a different script but whatever


#6

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


#7

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

#8

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


#9

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


#10

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)


#11

How you call the server event?

I see no error… so


#12

with a esx menu

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


#13

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

#14

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


#15

make a print before the TriggerClientEvent


#16

yep that printed the false


#17

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


#18

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


#19

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


#20

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