Hello everyone! I tried to make a script where It would check if a player indetifier exists in the db and if not it will change the players dimension on first connect and only on first connect. I have ran into a problem where the data from the server side of the script is not sent to the client.lua and does not execute. I have no idea why it is not working and I would really appreciate any help.
client.lua :
local firstServerConnect
local playerId = GetPlayerServerId(PlayerId())
RegisterNetEvent('connect:firstConnect')
AddEventHandler('connect:firstConnect', function(firstConnect)
if firstConnect then
firstServerConnect = true
print('Connect == False')
else
firstServerConnect = false
print('Connect == True')
end
end)
AddEventHandler("playerSpawned", function()
if firstServerConnect then
print('test')
print(playerId)
print(firstConnectFlag)
TriggerServerEvent('player:dimenzija', playerId)
end
end)
server.lua :
--Server Dimenzija del
RegisterNetEvent('player:dimenzija')
AddEventHandler('player:dimenzija', function(playerId)
SetPlayerRoutingBucket(playerId, playerId)
local playerDimenzija = GetPlayerRoutingBucket(playerId)
TriggerClientEvent('player:dimenzijaId', playerId, playerDimenzija)
end)
RegisterNetEvent('player:zamenjavaDimenzije')
AddEventHandler('player:zamenjavaDimenzije', function(playerId)
SetPlayerRoutingBucket(playerId, 0)
end)
-- Identifier check
AddEventHandler('playerConnecting', function(name, setKickReason, deferrals)
local source = source
local firstConnect
print(source)
local fullIdentifier = GetPlayerIdentifier(source, 0)
local parts = {}
for part in fullIdentifier:gmatch("[^:]+") do
table.insert(parts, part)
end
local identifier = parts[2]
-- Preverba SQL
MySQL.Async.fetchScalar('SELECT 1 FROM users WHERE identifier = ?', {identifier}, function(result)
if result then
firstConnect = false
print('Obstaja')
else
firstConnect = true
print('Ne obstaja')
end
TriggerClientEvent('connect:firstConnect', source, firstConnect)
deferrals.done()
print('Identifier:', identifier)
end)
end)