Indexing is not working

Hello, I have no clue why is this not working, it should work, but it doesn’t…

function module.GetPointTime(Player,NumberPoint)
	local PlayerData = module.CheckIfPlayerExistsInTable(Player)
	print(NumberPoint,PlayerData)
	if (PlayerData.Points[NumberPoint]) then
		print("Found player at getpointtime")
		print(os.clock() - PlayerData.Points[NumberPoint])
		print(PlayerData.Points[NumberPoint])
		return os.clock() - PlayerData.Points[NumberPoint]
	end
	return 0
end

Here’s a function i’m using to get a value from a position in “Points” at PlayerData…
The thing is:
When I print

print(NumberPoint,PlayerData)

It works perfect!
And numberpoint is clearly on PlayerData.Points, though, it doesn’t returns anything
Output:
image
image

1 Like

It nevers print “Found player at getpointtime”

It seems to be stuck on the if statement meaning it never found the Index make sure NumberPoint isn’t a string or if it is you can do
if PlayerData.Points[tonumber(NumberPoint)] then

No, NumberPoint is a number :smiley:

That’s strange, what does NumberPoint print out?

Number… 5 didn’t you read post

Try this?

function module.GetPointTime(Player,NumberPoint)
	local PlayerData = module.CheckIfPlayerExistsInTable(Player)
	print(NumberPoint,PlayerData)
	if (PlayerData[NumberPoint]) then
		print("Found player at getpointtime")
		print(os.clock() - PlayerData.Points[NumberPoint])
		print(PlayerData.Points[NumberPoint])
		return os.clock() - PlayerData.Points[NumberPoint]
	end
	return 0
end

no.
Points are at PlayerData.Points[NumberPoint]

Can you run this and see what it prints

for i, v in pairs(PlayerData.Points) do
	print(i, v, type(i), type(v))
end
1 Like

Well you are printing a different table then what you are checking.

1 Like

Here you go
image

Any idea why it won’t work? D:

Does this print nil?

print(PlayerData.Points[NumberPoint])
1 Like

Yeah, it returns nil
30characte

1 Like

My guess would be floating point rounding.
What data type did you intend the key of the value and NumberPoint to be (float or integer?)?

1 Like

Don’t know what you mean
I’ll show more of the code;

local module = {}

function module.CheckIfPlayerExistsInTable(p)
	if (module[p]) then
		return module[p]
	end
	return {Points = {},LastKey = ''}
end

function module.StorePointAndTick(Player,startpoint)
	if not (StarterPoint) then
		StarterPoint = startpoint
	end
	local PlayerData = module.CheckIfPlayerExistsInTable(Player)
	local PointKey = StarterPoint + 1
	StarterPoint += 1
	if (PlayerData.Points[PointKey]) then
		print("Found",PointKey,"Return :D")
		return; -- Makes sure we don't duplicate pointkey
	end
	PlayerData.Points[PointKey] = os.clock()
	PlayerData.LastKey = PointKey
	print("Add",PointKey)
	module[Player] = PlayerData 
end

function module.UntickLastPoint(Player)
	local PlayerData = module.CheckIfPlayerExistsInTable()
	local PointK = PlayerData.LastKey
	if (PointK) then
		if (PlayerData.Points[PointK]) then
			PlayerData.Points[PointK] = os.clock() - PlayerData.Points[PointK]
			--print("Unticking")
		end
	end
end

function module.GetPointTime(Player,NumberPoint)
	local PlayerData = module.CheckIfPlayerExistsInTable(Player)
	NumberPoint = NumberPoint and tonumber(NumberPoint)
	print(NumberPoint,PlayerData)
	if (PlayerData.Points[NumberPoint]) then
		print("Found player at getpointtime")
		print(os.clock() - PlayerData.Points[NumberPoint])
		return os.clock() - PlayerData.Points[NumberPoint]
	end
	return 0
end

return module

1 Like

Anyone has any idea what might be causing this?

Can you clearify what part of it don’t you know what I mean?
Does NumberPoint equal to the 5 key in the Points table (from floating point perspective)? It’ll only index if they rawequal to each other. (Test it via next or pairs)

2 Likes

So what do you expect me to do?
It won’t return the value, and I don’t know why,
local a = {
[1] = ‘hi’
}
local b = a[1]
print(b)
This is literally what I’m doing

And what do you mean with “floating point perspective”??

@sleitnick @daftcube ,very sorry for this @, could you check this out and attempt to help me?
For me now it’s just esoteric.