Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why doesn't the sword give damage on attack?

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)

2 comments

0

your remote event communication is extremely unsecure, some exploiter can loop through every player and kill them

0

Looks like you misspelled RemoteEvents in the LocalScript.

2 answers

✓ Accepted answer

#RemoteEvent Communication

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.

#LocalScript

--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)

2 comments

0

This would not work since damage doesn't replicate.

0

I can see where you are coming from with the exploiting. However, you aren't solving anything anyways since there is no communication with the server. What he/she should do is in the server script, automatically make the damage 15 and possibly create a distance checker (or some other check) to figure out if a player is actually hitting the player indicated.

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.