Hello thank you for taking the time to try and help me. I have a script that I am creating that needs the player street and zone on the server side. This is my current code.
client.lua
Citizen.CreateThread(function()
local zone = zones[GetNameOfZone(table.unpack(GetEntityCoords(PlayerPedId(),true)))]
local street = GetStreetNameFromHashKey(GetStreetNameAtCoord(table.unpack(GetEntityCoords(PlayerPedId(),true))))
while true do
TriggerServerEvent("sendpos", street, zone)
Citizen.Wait(100)
end
end)
server.lua
local playerstreet = {}
local playerzone = {}
RegisterServerEvent("sendpos")
AddEventHandler("sendpos", function(street, zone)
if zone ~= nil then
playerzone[source] = zone
else
playerzone[source] = "N/A"
end
if street ~= nil then
playerstreet[source] = street
else
playerstreet[source] = "N/A"
end
end)
Whenever I request the variable in lets say a chat message
RegisterCommand('location', function(source, args, RawCommand)
TriggerClientEvent('chatMessage', source, "[SYSTEM]", {255, 0, 0}, "Your location is " .. playerstreet[source] .. ", " .. playerzone[source] .. ""
end)
It will return , West Vinewood
NO MATTER what I do… UNLESS I restart the script while the server is running and then it works fine! If anyone has any ideas please get back with me!