Hey! So i’m making a pvp script and found a problem, when I click (or attack) my other friend cant.
I don’t know what’s happening nor do I know how to fix this.
Here is the code.
Variables:
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local debounce = false
local animation = script.Right
local animation2 = script.Left
local combo = 1
(keep in mind that I put it under character added since this is a server script)
event:
Remote.OnServerEvent:Connect(function(plr, weapon)
if debounce == false then
debounce = true
Now, i think this is where the problem rises, the part where I do the debounce, I’m not sure why this happens and I’m also not sure on how to fix this.
Thanks!
So I’m not sure because you’ve barely any code that shows us the problem and also can you show the output of the error? I’ve a minor theory that maybe you’re coding the PVP system under the PlayerAdded function, this is a big no no!
Reason:
When you use the PlayerAdded function each player that joins the game overwrites the previous player that joined the game, thus making the parameter “player” the new player that joined. This may be the problem however I need to see more of the code to actually catch grasp of what the problem specifically is.
I didn’t include the variables since i didn’t think it was that important but i guess i was wrong:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local Storage = ServerStorage:WaitForChild("Storage")
local Modules = Storage:WaitForChild("Modules")
local RaycastHitbox = require(Modules:WaitForChild("RaycastHitboxV4"))
local SwordRemote = ReplicatedStorage:WaitForChild("SwordRemote")
But then where do i put the “client sided” variables? I cant put it in the remote nor the player added.
“Client sided” variables as in:
Debounce, combo ect.
You see, its not that. I need it to be local to the player. If i just put it in the front, when a player sets the debounce to true, then the other player’s debounce is also true.
Your debounce system is currently server-wide, in other words when one client is debounced all clients are, consider using a debounce table instead, here’s an example of the former.
local players = game:GetService("Players")
local debounce = false
players.PlayerAdded:Connect(function(player)
if debounce then return end
debounce = true
print("Hello world!")
task.wait(10)
debounce = false
end)
This debounce system makes use of a single state variable which is shared by each player (client), so when one client activates the debounce the debounce becomes activated for every client. Here’s an example of the latter.
local players = game:GetService("Players")
local debounce = {}
players.PlayerAdded:Connect(function(player)
if debounce[player] then return end
debounce[player] = true
print("Hello world!")
task.wait(10)
debounce[player] = nil
end)
players.PlayerRemoving:Connect(function(player)
debounce[player] = nil
end)
Now the debounce system is unique to each player (client) and when one client activates the debounce it becomes activated for just that particular client. With this implementation you can remove leaving players from the table instantly (as it’s faster than waiting for the debounce cool down to expire).