Simply put, I’m running into a problem that may have a simple solution I just dont know. I have a script that is activated when players press a keybind and that activates a remote event that bounces through a server script to fireallclients so that i can create all the effects and part positioning for all the players on a different local script. It works perfectly if a player uses it one at a time, but if two players press the keybind at the exact same time, it completely breaks the effect and only one player has their effect activated and no one can activate the effect after that very well. I’m not sure what the issue is here but i’d love to find a solution. I’ve included a video of me sort of stress testing it with my alt account.
I haven’t found any sort of similar issue on the dev forum to help me which is why im writing this one.
This is the script i am using for the keybind. VVV
-- Input Begin ----------------------------------
UIS.InputBegan:Connect(function(key, IsTyping)
if Debounce1Key == false then
if key.KeyCode == Enum.KeyCode.Q and IsTyping == false then
IsUsing = true
IsHolding = true
keyHold:FireServer(flip)
if flip == true then
flip = false
elseif flip == false then
flip = true
end
end
end
end)
-- Input End ----------------------------------
UIS.InputEnded:connect(function(input)
if Debounce1Key == false and IsUsing then
if input.KeyCode==Enum.KeyCode.Q and IsHolding then
Debounce1Key = true
IsHolding = false
IsUsing = false
keyRelease:FireServer()
-- Change the wait for cooldown
wait(3)
Debounce1Key = false
end
end
end)
1 Like
Sounds like a problem on the server script. May we see it?
1 Like
This is what the local script bounces through to fire all clients
-- Replicated Storage ----------------------------------------------
local rp = game:GetService("ReplicatedStorage")
local keyHold = rp:FindFirstChild("GodOfSeaAssets"):FindFirstChild("GodOfSeaRemotes"):WaitForChild("QkeyHold")
local keyRelease = rp:FindFirstChild("GodOfSeaAssets"):FindFirstChild("GodOfSeaRemotes"):WaitForChild("QkeyRelease")
-- Debounces -------------------------------------------------------
local Debounce1 = false
local Debounce2 = false
-- Activate -----------------------------
keyHold.OnServerEvent:Connect(function(player, flip)
if Debounce1 == false then
Debounce1 = true
local playerSumsName = player.Name
keyHold:FireAllClients(playerSumsName, player, flip)
wait()
Debounce1 = false
end
end)
-- Deactive -----------------------------
keyRelease.OnServerEvent:Connect(function(player)
if Debounce2 == false then
Debounce2 = true
local playerSumsName = player.Name
keyRelease:FireAllClients(playerSumsName, player)
wait()
Debounce2 = false
end
end)
1 Like
You have a debounce for every time any player fires the event. You should have an independent method to debounce only the same player. You can do this by turning debounce into a table and using debounce2[player.Name] = true
1 Like
Let me give that a try real quick.
1 Like
Also using debounce for player input like this is not great. You could potentially have the key press be debounced but not the release. I would recommend instead having another system to track these abilities by player and ignoring keyhold for a ability on cooldown or in use and just doing nothing with release if not in use.
1 Like
I definitely don’t doubt that i did this wrong because I’m not great at using tables but this doesn’t seem to have fixed the issue.
-- Replicated Storage ----------------------------------------------
local rp = game:GetService("ReplicatedStorage")
local keyHold = rp:FindFirstChild("GodOfSeaAssets"):FindFirstChild("GodOfSeaRemotes"):WaitForChild("QkeyHold")
local keyRelease = rp:FindFirstChild("GodOfSeaAssets"):FindFirstChild("GodOfSeaRemotes"):WaitForChild("QkeyRelease")
-- Debounces -------------------------------------------------------
local Debounce1 = {}
local Debounce2 = {}
-- Activate -----------------------------
keyHold.OnServerEvent:Connect(function(player, flip)
if Debounce1[player.Name] then
return
end
print('uhhhhhh')
Debounce1[player.Name] = true
local playerSumsName = player.Name
keyHold:FireAllClients(playerSumsName, player, flip)
wait()
Debounce1[player.Name] = nil
end)
-- Deactive -----------------------------
keyRelease.OnServerEvent:Connect(function(player)
if Debounce2[player.Name] then
return
end
Debounce2[player.Name] = true
local playerSumsName = player.Name
keyRelease:FireAllClients(playerSumsName, player)
wait()
Debounce2[player.Name] = nil
end)
1 Like
and yes i had a different system for it I just swapped to this one temporarily because I’m testing techniques, i see what you mean though
1 Like
You implemented it correctly. What else is happening specifically other than one player retaining the trident?
1 Like
One player retains the trident and as you can see at the end of the video, after this bug happens, one of the players tridents stay in their hand no matter what, even if they press Q again to de equip it, besides that, the animation gets a little bugged but thats about all that happens.
1 Like
I think the trident is never deactivated and they end up holding two. Could you verify this in the explorer or by using prints when it gets equipped and removed? Maybe there is something wrong in the effect script.
1 Like
Yeah i get that they end up holding two tridents because one isnt deactivated, I could use prints for when it gets equipped and removed but I cant see those prints in-game when the bug actually happens. Should i be using the same table debounce for the effect script that I use in the server script?
1 Like
Dont know what the effect script does or why it uses a debounce. You shouldn’t need one for activate and deactive off the remote because the server is managing it. You can press F9 to see the console in game btw. Check if there are any errors. The other possibility is that the remote is not going through one of the times.
3 Likes
I didn’t know about the f9 for in game console, that’ll be super useful thanks. I added a debounce to the effect script because I’ve experienced problems on my past projects when I didn’t have it but i’ll take it out and do some more testing.
1 Like
After some testing without the effect script debounce it appears the issue was actually because i HAD a debounce in the effect script. There isnt any problem with activating the tridents at the same time now that i’ve taken that out so thanks! I’m gonna mark that as the solution.
2 Likes