Hello, I'm trying to make a custom sword. The problem is the scripting, the sword won't give damage to another humanoid. Help?
--LOCAL SCRIPT-- wait() script.Parent.blade.Touched:Connect(function(h) game.ReplicatedStorage.RemoteEventz.AttackToolE:FireServer(15, h) end)
--SERVER SCRIPT-- wait() Debounce = false game.ReplicatedStorage.RemoteEventz.AttackToolE.OnServerEvent:Connect(function(plr, Damage, Target) if Target.Parent:FindFirstChild('Humanoid') and Target.Parent.Name ~= plr.Name and Debounce == true then Debounce = false local enemy = Target.Parent.Humanoid enemy:TakeDamage(Damage) wait(1.5) Debounce = true end end)
your communication between the client and server is very unsecure as some exploiter can just loop through every player and kill them like this:
for _,v in pairs(game.Players:GetPlayers()) do game.ReplicatedStorage.RemoteEventz.AttackToolE:FireServer(-9999999999,v.Character.HumanoidRootPart) end
and they'd pretty much just ruin the entire server. You could just do all of this on the client, since it replicates to every client when you use :TakeDamage()
on a player. Also why your script didnt work is because you did and Debounce == true then
though your boolean is set to false without any line setting it to true before the if statement.
--client script local Debounce = false local player = game.Players.LocalPlayer script.Parent.blade.Touched:Connect(function(h) if h.Parent:FindFirstChildOfClass("Humanoid") and hit.Parent ~= player.Character and Debounce == false then Debounce = true local enemy = h.Parent.Humanoid enemy:TakeDamage(15) wait(1.5) Debounce = false end end)
Your issue is your debounce in the server script.
wait() Debounce = false game.ReplicatedStorage.RemoteEventz.AttackToolE.OnServerEvent:Connect(function(plr, Damage, Target) if Target.Parent:FindFirstChild('Humanoid') and Target.Parent.Name ~= plr.Name and Debounce == true then Debounce = false local enemy = Target.Parent.Humanoid enemy:TakeDamage(Damage) wait(1.5) Debounce = true end end)
The debounce is first defined as false. However, you check if the debounce is ever true
Debounce == true
. The debounce never changes to true, hence why the damage never gets taken by another player.