So I have a tool that shoots a projectile which creates a projectile on every client and would damage the player but it would cause the projectile to damage multiple times depending on the amount of players in the game.
Client:
local function DamagePlayer(hit)
local character = hit:FindFirstAncestorWhichIsA("Model")
if character then
local humanoid = character:FindFirstChildOfClass("Humanoid")
local player = game.Players:GetPlayerFromCharacter(character)
if humanoid and player and OwnerValue.Value and OwnerValue.Value.Team ~= player.Team then
Remotes.DamageHumanoid:FireServer(humanoid, 10)
end
end
end
Server:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
Remotes.DamageHumanoid.OnServerEvent:Connect(function(player, humanoid, damage)
if humanoid then
humanoid:TakeDamage(damage)
end
end)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local debounceTbl = {}
Remotes.DamageHumanoid.OnServerEvent:Connect(function(player, humanoid, damage)
local lastHitTime = 0
if debounceTbl[player.UserId] then
lastHitTime = debounceTbl[player.UserId]
end
if lastHitTime >= (os.time() - 1) then return end --adding a debounce of 1 second
if humanoid then
lastHitTime[player.UserId] = os.time()
humanoid:TakeDamage(damage)
end
end)
local function DamagePlayer(hit)
local character = hit:FindFirstAncestorWhichIsA("Model")
if character then
local humanoid = character:FindFirstChildOfClass("Humanoid")
local plr = game.Players:GetPlayerFromCharacter(character)
if humanoid and plr and OwnerValue.Value and OwnerValue.Value.Team ~= plr.Team and OwnerValue.Value == player then
local damage = humanoid.Health
Remotes.DamageHumanoid:FireServer(humanoid, damage)
end
end
end