Hi, I noticed that, when a player dies after triggering the debounce in this module (RemoteDB[Player]) and setting it to true, it seems that after they die it never gets to resetting the debounce back to false, hence always keeping it true and not allowing the code in the scope to run, how can I fix this?
local AllowedDB = {}
local RemoteDB = {}
function module.PublicPvPCheck(Player, arg)
if RunService:IsClient() then
local Table
coroutine.resume(coroutine.create(function()
if not RemoteDB[Player] then
RemoteDB[Player] = true
AllowedDB[Player] = false
Table = script.RemoteFunction:InvokeServer("PlayerTable")
if Table then
if table.find(Table, Player) then
AllowedDB[Player] = true
end
end
wait(10)
AllowedDB[Player] = false
RemoteDB[Player] = false
end
end))
end
return AllowedDB[Player]
end
I think a simple solution would be to make RemoteDB[Player] = false when the module is required, so that it’s set to false when they respawn and require it again. To achieve this we can connect to Player.CharacterAdded.
So a possible local solution could look something like this:
local AllowedDB = {}
local RemoteDB = {}
if game:GetService("RunService"):IsClient() then
local Player = game:GetService("Players").LocalPlayer
Player.CharacterAdded:Connect(function()
RemoteDB[Player] = false
end)
end
function module.PublicPvPCheck(Player, arg)
...
end
If you need to set it on the server instead then you can use a server script to connect to CharacterAdded for each player that joins and set RemoteDB[Player] = false in the function.
So a possible server solution could look something like this:
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function()
Module.RemoteDB[Player] = false
end
end)
You could also use Character.Humanoid.Died. Either way you would need the debounces to be returned for this to work, or return a function that can set them.