I’m trying to make a debounce whenever an explosion of a fireball hits a player and makes a debounce for each player that was hit.
local explosion_debounces = {}
local function Enter_Player_Debounce(debounce_table, player_Name)
table.insert(debounce_table, player_Name)
task.wait(1)
debounce_table[player_Name] = nil
end
Here I passed in one of the debounce tables and the player’s name as the parameters then after one second it should remove the player’s name from the dictionary but it didn’t work even though it should’ve. I don’t know how to solve this?
table.insert inserts only in integer, value pairs. This means every time you add something to the table using table.insert, the index is the size of the dictionary + 1. You would instead want to use:
Oh uh… about that… I didn’t create a table whenever a player joined (I’m new to this “advanced” debounce thing) I thought I could just insert a player’s name and then remove it
What ede means is table.insert(debounce_table, player_Name) inserts a number rather than the player’s name. Basically what the code above is doing is:
debounce_table = {
[1] = "the player's name",
}
So you’re not actually creating a way to reference the player. As stated before by ede, you should just do debounce_table[player_Name] = true as this creates a reference to the player in the table.
local function Enter_Player_Debounce(debounce_table, player_Name)
debounce_table[player_Name] = true
task.wait(1)
debounce_table[player_Name] = nil
end
If this works, and it should, give the check to ede2355, since all I did was just elaborate more on what he said
You can try to use table.find() to get the position of the debounce located in the table
local explosion_debounces = {}
local function Enter_Player_Debounce(debounce_table, player_Name)
table.insert(debounce_table, player_Name)
task.wait(1)
local index = table.find(explosion_debounces,player_name)
if index ~= nil then
table.remove(explosion_debounces, index)
end
end
I’m not quite sure what you you might want explain a bit further. But debouce[player_Name] = true sets whatever index, in this case that theplayer_name, to true. So if the index already exists in the table, itll just replace the index value to true
local explosion_debounces = {}
local function Enter_Player_Debounce(debounce_table, player_Name: string)
debounce_table[player_Name] = true
task.wait(1)
debounce_table[player_Name] = nil -- This will remove the player's debounce from the (debounce_table)
end
Refined code If you want to use it.
If you’re only using explosion_debounces for the argument then you should do this instead:
local explosion_debounces = {}
local function Enter_Player_Debounce(player_Name: string)
explosion_debounces[player_Name] = true
task.wait(1)
explosion_debounces[player_Name] = nil
end