Indexing is not working

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.

I believe @Blockzez is wanting to know whether the index is 5 exactly (integer 5), or if it is being rounded to 5 in the display (a floating point number such as 5.00000001). For more info on rawequal, you might find this post helpful: Rawset, Rawget and Rawequal - Help and Feedback / Scripting Support - DevForum | Roblox.

1 Like

So, why don’t I just floor the number, would that work?

You were right, it was a instance, how could I letted this pass.
Sad the new print(Instance) returns the name of it… makes it hard to debug

1 Like

I don’t really know how to mark as solution, anyway thanks so much to you, couldn’t understand what you said (tbh not much english I speak so)