When I try to increase my hit/count amount in my server script it just stays the same.
if not Character:FindFirstChild("Stun") then
print("WERKKKK")
CM.CombatStarted(Player, Character, Humrp, Count)
Count += 1
print(Count)
end
if Count == 4 then
Count = 0
end
-- \\ Module-Related Variables // --
local CM = require(script.CombatModule)
-- \\ Get-Service Variables // --
local RS = game:GetService("ReplicatedStorage")
-- \\ Events Variables // --
local Combat = RS.Combat
-- \\ Functions // --
Combat.OnServerEvent:Connect(function(Player, Count)
Count = 0
local Character = Player.Character
local Humanoid = Character.Humanoid
local Humrp = Character.HumanoidRootPart
if Character:FindFirstChild("Stun") then return end
if not Character:FindFirstChild("Stun") then
print("WERKKKK")
CM.CombatStarted(Player, Character, Humrp, Count)
Count += 1
print(Count)
end
if Count == 4 then
Count = 0
end
end)
Really this is it unless you’d like to see the local script aswell which passes Count down.
I see why. You are setting Count to 0 everytime the event is fired from the client. Meaning, even though it is increased by 1 on the first execution, on the second execution it is set back to 0.
Move the Count = 0 to somewhere outside of the event listener.
- \\ Module-Related Variables // --
local CM = require(script.CombatModule)
-- \\ Get-Service Variables // --
local RS = game:GetService("ReplicatedStorage")
-- \\ Events Variables // --
local Combat = RS.Combat
local Count = 0 -- moved it here
-- \\ Functions // --
Combat.OnServerEvent:Connect(function(Player, Count)
-- removed Count = 0
local Character = Player.Character
local Humanoid = Character.Humanoid
local Humrp = Character.HumanoidRootPart
if Character:FindFirstChild("Stun") then return end
if not Character:FindFirstChild("Stun") then
print("WERKKKK")
CM.CombatStarted(Player, Character, Humrp, Count)
Count += 1
print(Count)
end
if Count == 4 then
Count = 0
end
end)
Combat.OnServerEvent:Connect(function(Player, Count)
local Character = Player.Character
local HRP = Character.HumanoidRootPart
if Character:FindFirstChild("Stun") then return end
CM.CombatStarted(Player, Character, HRP, Count)
Count = if Count == 4 then 0 else Count + 1
end)
Why check for a child instance named “Stun” twice? local Count = 0 is going to be a state variable (flag) shared by every client connected to the server, if it needs to be player specific then a table value should be used instead.