Table Values Changing

Right, I’ll try and keep it simple. First of all, I must note this is working with ‘Cmdr’, but this changes nothing about it.

If you look at my table, named nameToIds, you’ll see it has the name of the voice channel and an ID. However, when I grab this (local id = nameToIds[voiceChannel]), it changes the ID value. My question is, why?

Code:

local replicatedStorage = game:GetService('ReplicatedStorage')
local webhookEvent = replicatedStorage.Remotes:FindFirstChild('webhookEvent') or nil
local nameToIds = {
	['Voice 1'] = 899378816407982140,
	['Voice 2'] = 899378859219234897,
	['Voice 3'] = 899378895017615420,
	['Waterloo'] = 975453408939094168,
}

return function (context, voiceChannel, player)
	if webhookEvent ~= nil then
		
		local id = nameToIds[voiceChannel]
		
		print(id)
		
		if id == nil then
			return "Channel doesn't exist."
		end
		
		local data = webhookEvent:Invoke((player or context.Executor), id)
		
		if type(data) == 'string' then
			return data
		elseif type(data) == 'boolean' and data == true then
			return "Successfully announced the event in chat."
		else
			return "Error grabbing the data -> Alternate data type"
		end
	else
		return "Error grabbing the data -> Missing event"
	end
end

What does it print when you try to print the id using print(id)?

If it printsnil it probably means that the “voiceChannel” does not exist in the table “nameToIds” if you get what i mean

It prints a different number, for example: 899378816407982140 → 899378816407982100

floating point precision loss, this website shows what happens to large numbers when converted to floats (f32) and doubles (f64). even if you print(899378816407982140) you’ll get a different number.

So how would I go about ‘fixing’ that?

Use smaller numbers, represent them as strings, or implement a big math library. All of these depend on what webhook function needs from the numbers of course.

  1. smaller numbers just work, but I have to assume you have large numbers for a reason
  2. strings require converting to and from and cannot be used in math. If these are identifiying numbers and not used for math then this should be fine
  3. kind of an all-out approach. here’s a lua file you should be able to require() for big number math. Only use this if you really need to operate on the numbers.

It’s an inherit issue in computers, the best explanation with real world examples of how it can affect games is this pannekoek video on super mario 64.

Thank you, can’t believe I didn’t think about the string idea.

You will face the same issue if you need to convert the strings back into numbers. Just a heads up!