Hello!
I’m quite new to FiveM development and lua in general, so I have question.
I’m creating a project where I have server.lua and client.lua:
server.lua
AreStrippersSpawned = false
RegisterNetEvent('nls:getAreStrippersSpawned')
AddEventHandler('nls:getAreStrippersSpawned', function ()
return AreStrippersSpawned
end)
RegisterNetEvent('nls:strippersSpawn')
AddEventHandler('nls:strippersSpawn', function ()
TriggerClientEvent('nls:strippersSpawn', -1)
AreStrippersSpawned = true
end)
client.lua
Citizen.CreateThread(function ()
print(areStrippersSpawned)
if areStrippersSpawned == true then
return
end
local playerServerId = GetPlayerServerId(PlayerId())
while areStrippersSpawned == false do
local playerPed = GetPlayerPed(GetPlayerFromServerId(playerServerId))
local playerCoords = GetEntityCoords(playerPed)
local distance = GetDistanceBetweenCoords(playerCoords.x, playerCoords.y, playerCoords.z, vanillaUnicornCoords.x, vanillaUnicornCoords.y, vanillaUnicornCoords.z, false)
if distance < 50 then
print(distance)
TriggerServerEvent('nls:strippersSpawn')
areStrippersSpawned = true
end
Citizen.Wait(1000)
end
end)
The issue that I have is that after I logout and login again AreStrippersSpawned is false. So my question is shouldn’t it be that server.lua script is only executed on server itself? How it works?