Boolean from client to server

Hello people, I have a server script which uses a function from client.lua. I want to set up a boolean in that client function and use it in server.lua? Is that possible or are there any alternatives?

You can push the boolean to the server using events

1 Like

Will give it a try, thanks :slight_smile:

Yeah I tried but I still can’t get it to work. Can someone help me make an event which sends true or false from client to server?

-- server
RegisterNetEvent("gimme")
AddEventHandler("gimme", function(boolean)
    print("boolean is now " + boolean)
end)

-- client
TriggerServerEvent("gimme", true)

I think it works but I don’t know why this doesn’t work properly. Even if gimme is true I still get the items. :confused: Here’s the code:
server.lua

local function m_breakvan(menu)
    local user = menu.user
	local vmod = "mule"
	local inv = user:getInventoryWeight()
	local maxinv = user:getInventoryMaxWeight()

	local model = self.remote.isPlayerNearModel(user.source, vmod, 5)
	if maxinv - inv > 5 then
	if user:tryTakeItem("plasmacutter", 1, true) or user:hasPermission(lang.perms.lockpick_noapt()) then
	if model then
	gimme = false
	self.remote.breakBankVan(user.source, 30)
	if gimme == true then
	TriggerClientEvent('mythic_notify:client:SendAlert', source, { type = 'error', text = 'Morate biti blizu neokupiranog oklopnog kamiona', length = 5000 })
	else
	local nagrada = "plastika"
	local jedan = math.random(1,10)
	if jedan < 5 then
	nagrada = "aluminijum"
	user:tryGiveItem(nagrada,math.random(1,5))
	else
	user:tryGiveItem(nagrada,math.random(1,5))
	end
	end
    else
        TriggerClientEvent('mythic_notify:client:SendAlert', source, { type = 'error', text = 'Morate biti blizu neokupiranog oklopnog kamiona', length = 5000 })
    end
	    else
		TriggerClientEvent('mythic_notify:client:SendAlert', source, { type = 'error', text = 'Potreban vam je aparat za secenje.', length = 5000 })
        
	end
			else
		TriggerClientEvent('mythic_notify:client:SendAlert', source, { type = 'error', text = 'Morate imati minimum 5kg slobodnih u inventaru.', length = 5000 })
        
	end
end

client.lua

function AddonsV:breakBankVan(wait)
    local pos = GetEntityCoords(GetPlayerPed(-1))
    local entityWorld = GetOffsetFromEntityInWorldCoords(GetPlayerPed(-1), 0.0, 20.0, 0.0)
    local rayHandle = CastRayPointToPoint(pos.x, pos.y, pos.z, entityWorld.x, entityWorld.y, entityWorld.z, 10, GetPlayerPed(-1), 0)
    local _, _, _, _, vehicleHandle = GetRaycastResult(rayHandle)

    if DoesEntityExist(vehicleHandle) then			
		local isopen = GetVehicleDoorAngleRatio(vehicleHandle,2) and GetVehicleDoorAngleRatio(vehicleHandle,3)
		if (isopen == 0) then	

            local prevObj = GetClosestObjectOfType(pos.x, pos.y, pos.z, 10.0, GetHashKey("prop_weld_torch"), false, true, true)

            if (IsEntityAnObject(prevObj)) then
                SetEntityAsMissionEntity(prevObj)
                DeleteObject(prevObj)
            end

            TaskStartScenarioInPlace(GetPlayerPed(-1), "WORLD_HUMAN_WELDING", 0, true)
			self.remote.breakVan()
            Citizen.Wait(wait * 1000)
			SetVehicleDoorOpen(vehicleHandle, 2, false)
            SetVehicleDoorOpen(vehicleHandle, 3, false)				
            ClearPedTasksImmediately(GetPlayerPed(-1))
		else
			exports['mythic_notify']:SendAlert('error', 'Aparat za secenje mora dodirivati vozilo.', 5000)
			TriggerServerEvent("gimme", true)
		end
		else 
		exports['mythic_notify']:SendAlert('error', 'Aparat za secenje mora dodirivati vozilo.', 5000)
		TriggerServerEvent("gimme", true)		
	end
end