Local script fires RemoteEvent to Server but is effecting all players?

Hey there,

i seem to have created an unwanted issue within my code, Basically as seen in a GIF below when a Player swings the weapon a Local script fires an Event to the Server which then deals Damage based on a Touched event but its allowing any Player to damage instead of just the person who fires the event?

https://gyazo.com/145143593a12120cfbaf5f92fa077def

Local Script:

local input = game:GetService(“UserInputService”)
local rs = game:GetService(“ReplicatedStorage”)
local Mace = rs:WaitForChild(“Mace”)
local player = game:GetService(“Players”).LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
local human = char:WaitForChild(“Humanoid”)
local idle = human.Animator:LoadAnimation(script.Parent:WaitForChild(“Idle”))
local hurt = script.Parent.Hurt.Value
local wep = script.Parent
local cooldown = .9
local db = false
local equip = false
local swordsounds = script.Parent.Handle
local trail = script.Parent.Ball.Trail

wep.Equipped:Connect(function(mouse)
equip = true
swordsounds.Out:Play()
idle:Play()
wep.Unequipped:Connect(function(mouse)
equip = false 
swordsounds.PutAway:Play()
idle:Stop()
end)

input.InputBegan:Connect(function(input,isTyping)
if isTyping then
    return
    elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
    if db == false and equip == true then
    trail.Enabled = true
    db = true
    print("Clicked")
    Mace:FireServer()
    wait(cooldown)
    db = false
    trail.Enabled = false
        end
    end
end)

end)

Script:

local rs = game:GetService(“ReplicatedStorage”)
local Mace = rs:WaitForChild(“Mace”)
local wep = script.Parent
local hurt = script.Parent.Hurt.Value
local anims = script:WaitForChild(“Anims”)
local swingsound = script.Parent.Handle.Swing
local sounds = game.ServerStorage.Sounds
local soundsclone = sounds:Clone()

local list2 =
{
anims:WaitForChild(“Heavy”),
anims:WaitForChild(“Round”),
}

Mace.OnServerEvent:Connect(function(player,cooldown) print(player.Name)
local char = player.Character
soundsclone.Parent = char.Head
local human = char:WaitForChild(“Humanoid”)
local index = math.random(1, 2)
local picked = list2[index]
local attack = human:LoadAnimation(picked)
swingsound:Play()
attack:Play()

    hurt = true 
    for _, child in pairs(wep:GetChildren()) do
        if child:IsA("Part") then   
        child.Touched:connect(function(hit)
            if hit.Parent:FindFirstChild("Humanoid") ~= nil and hurt == true then 
                soundsclone.Hit:Play()
                hit.Parent:FindFirstChild("Humanoid"):TakeDamage(25)
                hurt = false

end
end)
end
end
end)

Thank you, i’m sure its a simple fix but I’m unable to figure it out.

I think you’re making every part hurt a player. Try just referencing the handle and see if that works.

Nevermind. I know why. The remote always gets called when equipped so this is probably why

The remote is fired if Equipped == true and MouseButton1 has been clicked tho?, Nothing happens if they just equip

Try using the Activated function instead

If thats just replacing Equipped with Activated then it didnt work…

Then just do it all in a server script

Still stuck on this if anyone else sees this :slight_smile:

This is happening because the remote event is placed in replicated storage. That would mean that every server script would detect it when it’s fired. If you want it to only fire for one person, place the RemoteEvent in the tool and reconfigure everything from there

2 Likes