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

How can I make my sword not one hitting people?

Hi I need some help with making a sword, that doesn't one hit players. I tried fixing it so many times but It wont work. I need some help! Here is my script:

local sword = script.Parent
debounce = 2
notfree = false


local function slash()
	if notfree == false then
		
		sword.blade.Touched:Connect(function(hit)
			human = hit.Parent:FindFirstChild("Humanoid")
			if human then
				human:TakeDamage(20)
			end
			notfree = true
		end)
	end
end

sword.Activated:Connect(slash)
sword.Deactivated:Connect(function()
	wait(debounce)
	notfree = false
end)	

2 comments

0

WHat do you mean by "Not One Hitting a player"?

0

I mean dealing only some damage and not instantly killling them.

2 answers

Just change


human:TakeDamage(20)


to


human:TakeDamage(100)


6 comments

0

and it will be a one shot when you use the sword

0

bro i want it to not one shot

0

oh

0

well I think I know the problem in the code it says when the blade is touching the human it does damage so put down a dummy and dont swing the sword, just touch the sword on the dummy and see if it does damage, if it does maybe add a wait after Human:takedamage(20)

0

i want it when i activate it to do damage, it has an animation and everything but it just one shot kills

0

so it does damage when your not swinging?

The problem is that your sword is hitting the other player multiple times when it slashes.

There is a simple fix for this but sometimes it can be inconsistent.

The fix is adding a cooldown when the sword touches a player. This makes it so that if your sword touches a player, it will start the cooldown and all the following touches will be ignored until the cooldown ends.

local sword = script.Parent
debounce = 2
cooldown = false
notfree = false


local function slash()
    if notfree == false then

        sword.blade.Touched:Connect(function(hit)
            human = hit.Parent:FindFirstChild("Humanoid")
            if human then
		if cooldown == false then
			cooldown = true
			human:TakeDamage(20)
			wait(0.1)
			cooldown = false
		end
            end
            notfree = true
        end)
    end
end

sword.Activated:Connect(slash)
sword.Deactivated:Connect(function()
    wait(debounce)
    notfree = false
end)    

If this doesn't work then make the waiting time for the cooldown longer

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