Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I make my sword not one hitting people?

Asked by 2 years ago

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)    
0
WHat do you mean by "Not One Hitting a player"? silver_robot682 0 — 2y
0
I mean dealing only some damage and not instantly killling them. koce1234 0 — 2y

2 answers

Log in to vote
0
Answered by 2 years ago

Just change


human:TakeDamage(20)


to


human:TakeDamage(100)


0
and it will be a one shot when you use the sword Iownrobloxp 44 — 2y
0
bro i want it to not one shot koce1234 0 — 2y
0
oh Iownrobloxp 44 — 2y
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) Iownrobloxp 44 — 2y
View all comments (2 more)
0
i want it when i activate it to do damage, it has an animation and everything but it just one shot kills koce1234 0 — 2y
0
so it does damage when your not swinging? Iownrobloxp 44 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

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

Answer this question