LUA Script

Cant seem to get around this error!
for k, v in pairs(player.GetAll()) do
mytime = v:TimeConnected()
end

Works the first time then the second time it is ran I get this error

[ERROR] lua/autorun/test.lua:27: attempt to call method ‘TimeConnected’ (a nil value)

It’s serverside only.

Are you running it clientside? It looks like a serverside method.

Edit:
Ninja’d

Yea, its getting ran server side.

[editline]5th March 2013[/editline]

I know that.

Show us your full code.

function checkalltimes()
for k, v in pairs(player.GetAll()) do
mytime = v:TimeConnected()
print("This <<< " … mytime)

if tonumber(mytime) > tonumber(“59”) then
times[v:UniqueID()]= mytime + math.floor(“3600”)

elseif tonumber(mytime) > tonumber(times[v:UniqueID()]) then
print(“Negative”)

end

end
end

I uh…
Why are you wrapping every number in quotes?
[lua]
function checkalltimes()
for k,v in pairs(player.GetAll()) do
times[v:UniqueId()]=v:TimeConnected()
end
end
[/lua]
I don’t know why you’d want to do this, but that’s a much more simple way to do it.

In what way is that different than what I had?
:facepalm:

What you were doing does nothing.
Why not just stick to using :TimeConnected instead of storing it in a variable?

How does it do nothing?
mytime = v:TimeConnected() <— Sets the var to the connected time
print("This <<< " … mytime)

if tonumber(mytime) > tonumber(“59”) then <---- checks if the var is grater than 59

How does that do nothing?

What would you do for it

First you should just use mytime>59
Secondly, times[v:UniqueID()]= mytime + math.floor(“3600”) would just set times[blah] to your time connected + 3600(you should also just use 3600, not math.floor(3600))
Why are you doing this? There’s bound to be a better way than what you want.

Just need a command to run on on each player that is on the server for X time intervals.
Like hour 1 it runs print(“You were on the server for one hour”). Then the second hour its like print(“blah blah blah”) then third its like (“feruiwdf”) etc…

Basically : You are on server for X time Y happens.

I still need help.