How can i set a player's spawn location

Hello !

I am new to Lua coding and GLua and i’m trying to make some cool things :stuck_out_tongue: I am currently trying to make a custom spawn location, let me explain :
I get x, y, z floats specific to each player and i’d like to spawn the player at those coords.

I tried ply:SetPos in GM:PlayerSpawn : dont work
I tried to create an entity on GM:PlayerSpawn and use it on PlayerSelectSpawn : don’t work because idk which player should use which entity and if i put it in class name, then error entity dont exists

If you have any idea please help me , thx :smiley:

[editline]20th November 2016[/editline]

Problem solved

I had to add a
function GM:PlayerSpawn ( ply )
– Get data variable here
timer.Simple( 1, function()
ply:SetPos(Vector(data.position_x, data.position_y, data.position_z))
end )

But could you tell me an optimal delay ?

If you set a timer to 0 instead of 0.000001 or some crazy tiny number, it runs the function next server or client tick (whichever the code is being run on - I’m assuming server for your case).

If the timer’s delay is 0 it attempts to run the timer in the next frame. So possibly 0. Trial and error is the best problem solver here.

Thank you guys, atm i’m using 0.005 , going to try 0 and edit this message to tell the result if someone wants to do the same

I have an other problem, how do i store player’s informations ? Not for long time storage ( i already implemented mysql fetch and save ), but when i load my players infos from mysql on is initial spawn or connect, where should i store his informations like his money ? i tried an array in _G but dont work, what should i do please ? These informations will be saved again on demand of player or at disconnects or every x minuts

I think i should edit metatable of player to set some variables ? Am i right ?

if you want a vector, you can do something like this:
function GM:PlayerSelectSpawn( pl )

I’ll try that later, but i think i already tried it didnt work

[editline]25th November 2016[/editline]

I confirm this dont work, what i finaly did is add a delay inside playerspawn and put spawn informations as network informations (SETNW…)