I want to add something to the table.
I don’t know how to.
I tried looking for solutions, but couldn’t find any.
For example, I want it to be like
local Table = {
["PlayerName"] = {
["MoveName"] = false,
["MoveName"] = false
}
}
But instead when I try to add it with the function I made.
local Table = {
["PlayerName"] = {
["MoveName"] = false
}
}
Here are the scripts
Debounce Module:
local Debounce = {}
local Debounces = {}
function Debounce:AddDebounce(Player, Move)
local Success, Error = pcall(function()
Debounces[Player.Name] = {
[Move] = false
}
print(Debounces)
end)
if not Success then
Debounce:AddDebounce(Player, Move)
warn(Error)
end
end
return Debounce
Moveset Module:
local Moveset = {
["Combat"] = {
["M1"] = {
Name = "M1";
Cooldown = .25;
FinishCooldown = .7;
Key = Enum.UserInputType.MouseButton1
},
["Block"] = {
Name = "Block";
Cooldown = .25;
Key = Enum.KeyCode.F
},
["Dash"] = {
Name = "Dash";
Cooldown = 1;
Key = Enum.KeyCode.Q
}
}
}
return Moveset
Here is the main script
local Moveset = require(script.Parent.Modules.Moveset)
local Debounce = require(script.Parent.Modules.Debounce)
game.Players.PlayerAdded:Connect(function(Player)
Debounce:AddDebounce(Player, Moveset.Combat.M1.Name)
Debounce:AddDebounce(Player, Moveset.Combat.Block.Name)
end)
2 Likes
if not Success then
-- the error most likely wouldn't go away by itself so be careful with recursion
warn(Error)
print(Player, Move)
end
what exactly do you need help with?
Whenever I add a new debounce into the script it removes the old one for example I add a debounce it makes it like this
local Table = {
["PlayerName"] = {
["MoveName"] = false
}
}
and then I try to add another one, but then it resets it and it replaces it with the new one. I just want to add it in the PlayerName.
that’s because you were changing the PlayerName’s whole table instead of indexing a new move
Debounces["PlayerName"] = {
-- resetting PlayerName's debounces
}
print(Debounces)
-- expected output
["PlayerName"] = {}
Debounces["PlayerName"]["MoveName"] = false
print(Debounces)
-- expected output
["PlayerName"] = {
["MoveName"] = false
}
How do I index a new move in the PlayerName’s table.
Debounces["PlayerName"]["MoveName"] = true -- changing a value
-- this line is in my previous reply
note if a move already exists in the player’s debounces then you’ll be changing that move instead of creating a new one
-- this is expected
["PlayerName"] = {
["MoveName"] = true
}
-- this should not happen since there would be duplicate moves
["PlayerName"] = {
["MoveName"] = false
["MoveName"] = true
}
No that is what I want to happen.
For example I have 2 moves M1 and Block
There is a cooldown so I need 2 debounces
It will insert there name inside of it.
["PlayerName"] = {
["M1"] = false
["Block"] = false
}
yes that’s what will happen
i was saying that you can get a player’s move debounce without creating the same one
we were using “PlayerName” and “MoveName” in the examples
How would I get a player’s move debounce without creating the same one?
By the way, mine is server-sided not client.
["Bones"] = {}
-- i have no debounces so i create a new one (which is what your function will do)
Debounces["Bones"]["Block"] = false
["Bones"] = {
["Block"] = false
}
-- since i have a "Block" debounce i can change it without creating a new "Block" debounce
Debounces["Bones"]["Block"] = true
Yes, but I want to add multiple debounces in one for example.
I have 2 moves M1 and Block.
I want to make it so it adds a new debounce, but instead it is only creating one debounce.
For example I have a function that adds a debounce everytime.
I use that function and add a debounce then when I use it again it adds a debounce but removes the old ones.
Basically I just want to add something in the PlayerName table.
then your original code should work
My original code doesn’t work since when I use the function it adds a debounce.
Then when I use it again to add another debounce it adds it, but removes the old debounce for example I use the function and it adds M1.
local Table = {
["PlayerName"] = {
["M1"] = false
}
}
But when I want to add a block debounce it comes out like this.
local Table = {
["PlayerName"] = {
["Block"] = false
}
}
I want it to come out like this
local Table = {
["PlayerName"] = {
["M1"] = false,
["Block"] = false,
}
}
i misread thought you were saying you wanted the old ones to be removed
earlier i was saying you needed to change this
-- this would remove the old debounces
Debounces[Player.Name] = {
[Move] = false
}
to this
-- this would only insert a new debounce
Debounces[Player.Name][Move] = false
It comes out with an error
ServerScriptService.Modules.Debounce:6: attempt to index nil with 'M1'
Here is the new code for the debounce module.
local Debounce = {}
local Debounces = {}
function Debounce:AddDebounce(Player, Move)
Debounces[Player.Name][Move] = false
end
return Debounce
I will change it in the future to see if they already had the move set or something like that.
-- add 'Player' to debounces if they don't exist
Debounces[Player.Name] = Debounces[Player.Name] or {}
Debounces[Player.Name][Move] = false
system
(system)
Closed
June 17, 2023, 7:15pm
20
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.