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

Sword still damaging players even when it shouldn't?

Asked by 2 years ago

Hi, I'm trying to make an ability for a sword which does a lot of damage in one hit. It does the damage, but it keeps damaging the opponent even when you're just holding the sword over them. Ive tried making it wait and set the takedamage script to 0 but it still won't work. Help would be much appreciated!

here is the script in server script service which gets activated once a remote event is fired:

game.ReplicatedStorage.Bat.OnServerEvent:Connect(function(player)
    local char = player.Character
    local bat = char:FindFirstChild("Bat")

    wait(1.2)

    bat.Handle.Bonk:Play()
    bat.Handle.bat_hit:Play()

    bat.Handle.Touched:Connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") then
            if hit.Parent.Name ~= player.Name then
                hit.Parent.Humanoid:TakeDamage(1.5)
            end
        end
    end)

    wait(.5)

    bat.Handle.Touched:Connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") then
            if hit.Parent.Name ~= player.Name then
                hit.Parent.Humanoid:TakeDamage(0)
            end
        end
    end)
end)

1 answer

Log in to vote
1
Answered by 2 years ago
Edited 2 years ago

What's up?

I have found a pretty solid solution to your question.

I have answered this in a similar question of yours (https://scriptinghelpers.org/questions/129322/sword-not-knocking-back-players-when-used), but I will help again anyhow.

To start off, :TakeDamage() won't stop them taking damage! :TakeDamage(0) just means it won't make them loose health.

Anyhow, DEBOUNCE IS HERE TO SAVE THE DAY!!!

Inside your script:

game.ReplicatedStorage.Bat.OnServerEvent:Connect(function(player,bat)
    local debounce = false
    local char = player.Character

        wait(1.2)

    bat.Handle.Bonk:Play()
    bat.Handle.bat_hit:Play()

    bat.Handle.Touched:Connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") and debounce == false then
            if hit.Parent.Name ~= player.Name then
                hit.Parent.Humanoid:TakeDamage(1.5)
            end
        end
    end)

    wait(.5)

    debounce = true
end)
0
Thank you so much! I really cant thank you enough for this. I've been waiting for so long to get an answer. Thank you! DriBowser 55 — 2y
0
Any time! :D LikeableEmmec 470 — 2y
Ad

Answer this question