So i changed it to the original and made it a remote event, what I was trying to achieve yesterday was for the event to fire only for the player that slashes.
Receiving event script:
local lastslashEvent = game:GetService("ReplicatedStorage").Events.LastSlash
local blockingevent = game:GetService("ReplicatedStorage").Events.PlayerBlocking
local slasheffect = game.ReplicatedStorage.VFX.SwordVfx.Slash.Hit
local slashhit = game.ReplicatedStorage.VFX.SwordVfx.SwordSlash
local TweenService = game:GetService("TweenService")
local function moveBackward(humanoid)
local startPosition = humanoid.RootPart.Position
local endPosition = startPosition - humanoid.RootPart.CFrame.lookVector * 0.5
local tweenInfo = TweenInfo.new(0.4, Enum.EasingStyle.Quad)
local tween = TweenService:Create(humanoid.RootPart, tweenInfo, {Position = endPosition})
tween:Play()
end
damageEvent.OnServerEvent:Connect(function(player, humanoid, damageAmount, humanoidAttacker)
local slasheffect1 = slasheffect:Clone()
slasheffect1.Parent = humanoid.Parent.HumanoidRootPart
local slashhit1 = slashhit:Clone()
slashhit1.Parent = humanoid.Parent.HumanoidRootPart
slashhit1:Play()
humanoid:TakeDamage(5)
humanoid.WalkSpeed = 2
player.Character.Humanoid.WalkSpeed = 4
moveBackward(humanoid)
wait(0.1)
slasheffect1:Destroy()
wait(0.5)
player.Character.Humanoid.WalkSpeed = 10
humanoid.WalkSpeed = 10
end) ```
local tool = script.Parent
local hitboxSize = Vector3.new(5, 1, 5)
local damageEvent = game.ReplicatedStorage.Events.DamageEvent
local damageAmount = 5
local humanoidAttacker = game.Players.LocalPlayer.Character
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoidrootpart = character:WaitForChild("HumanoidRootPart")
local humanoid = character:WaitForChild("Humanoid")
local anim = tool.SwordAnimations:WaitForChild("Block")
local animator = humanoid:FindFirstChildOfClass("Animator")
local function SwordSlashes()
local numSlashes = 0
local lastSlashTime = tick()
local slashCooldown = 0
local isPlayingAnimation = false
local function Slash()
if numSlashes >= 5 or isPlayingAnimation then
return
end
local timeSinceLastSlash = tick() - lastSlashTime
if timeSinceLastSlash < slashCooldown then
return
end
if timeSinceLastSlash > 2 and numSlashes > 0 then
numSlashes = 0
wait(3)
end
local slashAnimName = "Slash" .. (numSlashes + 1)
local slashAnim = tool.SwordAnimations:WaitForChild(slashAnimName)
local slash = animator:LoadAnimation(slashAnim)
if not isPlayingAnimation and not slash.IsPlaying then
isPlayingAnimation = true
slash:Play()
slash:AdjustSpeed(1.3)
local hitbox = Instance.new("Part")
hitbox.Name = "Hitbox"
hitbox.Anchored = true
hitbox.Size = hitboxSize
hitbox.CanCollide = false
hitbox.Transparency = 0.5
hitbox.CFrame = humanoidrootpart.CFrame * CFrame.new(0, 0, -3)
hitbox.Parent = workspace
for _, humanoid in ipairs(workspace:GetDescendants()) do
if humanoid:IsA("Humanoid") and humanoid.Parent ~= character then
local distance = (humanoid.RootPart.Position - hitbox.Position).Magnitude
if distance < hitboxSize.magnitude / 2 then
damageEvent:FireServer(humanoid, damageAmount, humanoidAttacker)
end
end
end
slash.Stopped:Wait()
numSlashes = numSlashes + 1
lastSlashTime = tick()
isPlayingAnimation = false
hitbox:Destroy()
end
end
spawn(function()
while true do
wait(0.1)
local timeSinceLastSlash = tick() - lastSlashTime
if timeSinceLastSlash > 1 and numSlashes > 0 then
numSlashes = 0
end
end
end)
return Slash
end
local slashAction = SwordSlashes()
tool.Activated:Connect(slashAction)
The logic here searches the entire workspace for every humanoid that is not the character and is within range then fires the event. Try limiting this to just the humanoids involved.
How would I do that tho, I dont think thats the problem either tho is it? If i limit it for only the humanoids involved it would still fire the event for every player right, The issue is that it adds damage to the count how many players are in the game ex. 2 players is 10 dmg instead of 5, if im wrong my bad, but im not sure if its the fix.
Ok right, I see what you mean now, you want to be able to damage every other player within range.
As the problem you describe seems to be linked to the number of players in the game, (and I can’t find anything which would cause this in this section of code), you may need to check any .playerAdded or .characterAdded events you have.
Say if, for example, one of these events adds the remote event connection, when another player/character is added it will duplicate the connection.
If you add a print(player) statement to the serverscript when the remote is fired you’ll be able to tell if this is then the issue as you should see multiple firings.