Spawning player

Hi, I have that script, but when i join on serwer, the loading screen is closing, player (as i think is spawned) but i have black screen and after ~2/3 minutes the game freeze. Any advices?

Blockquote
local function freezePlayer(id, freeze)
local player = id
SetPlayerControl(player, not freeze, false)

local ped = GetPlayerPed(player)

if not freeze then
    if not IsEntityVisible(ped) then
        SetEntityVisible(ped, true)
    end

    if not IsPedInAnyVehicle(ped) then
        SetEntityCollision(ped, true)
    end

    FreezeEntityPosition(ped, false)

    SetPlayerInvincible(player, false)
else
    if IsEntityVisible(ped) then
        SetEntityVisible(ped, false)
    end

    SetEntityCollision(ped, false)
    FreezeEntityPosition(ped, true)

    SetPlayerInvincible(player, true)

    if not IsPedFatallyInjured(ped) then
        ClearPedTasksImmediately(ped)
    end
end

end

function spawnPlayer()
local ped = GetPlayerPed(-1)
SetEntityCoords(ped,tonumber("-287"),tonumber(“6127”),tonumber(“35”),1,0,0,1)
ShutdownLoadingScreen()
end

AddEventHandler(“playerSpawned”, function()
local model = GetHashKey(“s_m_y_blackops_02”)
local playerPed = GetPlayerPed(-1)
RequestModel(model)
while not HasModelLoaded(model) do
Citizen.Wait(0)
end
SetPlayerModel(PlayerId(), model)
SetModelAsNoLongerNeeded(model)

GiveWeaponToPed(playerPed, GetHashKey("WEAPON_PISTOL"), 100, false)
GiveWeaponToPed(playerPed, GetHashKey("WEAPON_AUTOSHOTGUN"), 100, false)

end)

Citizen.CreateThread(function()
while true do
Citizen.Wait(50)
local playerPed = GetPlayerPed(-1)
if playerPed and playerPed ~= -1 then
if NetworkIsPlayerActive(PlayerId()) then
–if (diedAt and (GetTimeDifference(GetGameTimer(), diedAt)> 2000)) then
Citizen.Trace(“forcin’ spawn\n”)
spawnPlayer()
–end
end
if IsEntityDead(playerPed) then
if not diedAt then
diedAt = GetGameTimer()
end
else
diedAt = nil
end
end

end

end)