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.

1 comment
Very sure the server IS all players