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

Sword not knocking back players when used?

Asked by 2 years ago

Im not sure if this type of question is ok, but I really have no clue on how to do this. Basically, im trying to make an ability for a sword when you press e, it knocks the opponent in front back. But I don't really know how to do this. I would REALLY appreciate help.

here is the script in server script service, which gets activated when the remote gets fired from the sword:

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(3)
            end
        end
    end)
end

1 answer

Log in to vote
0
Answered by 2 years ago

I answered a question 2 days ago asking "How to make an egg launcher like in the egg hunts?" and I have a similar answer here for you.

BodyForce IS deprecated, but it still works.

We just have to do a quick copy 'n paste with that code aaaand...

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

    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
                if debounce == false then
                    debounce = true
                    local force = Instance.new("BodyForce",hit.Parent.HumanoidRootPart)
                    force.Force = bat.Handle.CFrame.lookVector * 10500 -- Change this depending on how far you want people to go

                    hit.Parent.Humanoid:TakeDamage(25)

                    game.Debris:AddItem(force,.5)
                end
            end
        end
    end)
end -- Change this to end) or your script won't work at all.

ALSO! I have some changes. I added a debounce, a 'bat' argument, and, well, the force. I also upped the damage.

We also have a client change. Insert a LocalScript INSIDE the tool, not inside the handle but the TOOL.

Then add:

local plr = game.Players.LocalPlayer

script.Parent.Activated:Connect(function()
    game.ReplicatedStorage.Bat:FireServer(script.Parent)
end)

This is simple, the bat remote event fires an argument of our bat. Adding the player is not needed, since this is the client.

I won't get down in big details, but if you would like me to, go ahead.

0
Also, remove your original LocalScript or else it may cause an error. LikeableEmmec 470 — 2y
0
Thanks! I already did have a local script inside of the actual tool, not the handle and I made it fire an event to activate it, but i'll try the other script you sent! Thanks again! DriBowser 55 — 2y
0
It works!! Thank you SO MUCH man. I really needed an answer for this because i just couldnt figure out why it would do this. I really apprecicated the help. Thank you! DriBowser 55 — 2y
0
Your welcome! LikeableEmmec 470 — 2y
Ad

Answer this question