Ban Hammer for King Of The Hill game

Hello! I have been making a minigame place for quite a while now and I’m stuck on a King Of The Hill minigame. The actual system is done but I am completely lost on how to make a hammer/bat/tool that can be used to knock other players off the hill. I have tried several videos on Youtube and figuring it out myself on Roblox Studio but nothing seems to work. If you don’t know what I mean by a hammer, play around the game “Epic Minigames” until you get the King Of The Hill game mode. Any feedback would be greatly appreciated. Thank you! :grinning:

1 Like

Use a .Touched connection or use Swordphins Raycast Module on the hammer end of the tool. You can create a script (server) inside the tool which connects the Tool.Activated event, which basically fires whenever a player clicks while having the tool equipped, to make the player play an animation to make the hammer swing, that is also when you should raycast/allow your touched connection to fling players. Whenever you detect a humanoid, you can add a BodyVelocity to their HumanoidRootPart and set the Velocity property to the opposite of their LookVector (behind them) with a positive Y-axis to make them go upwards and backwards. Keep in mind, BodyVelocity velocity property takes a world position, meaning it will move the part in the velocity that you specified, it will not move your rootpart towards a specific goal position. You should also use the Debris service to remove the BodyVelocity from the player’s rootpart like so: game:GetService("Debris"):AddItem(myBodyVelocity, 0.2). If you are confused about anything, let me know.

1 Like

This shall require some Debounces, Touched functions, and some Cool variables, here’s an example with some minor comments:

local Tool = script.Parent
local Debounce = false --A debounce is basically a cooldown until the tool activates again

local function HitDetection(Hit) --The hitpart is the first parameter of a Touched event
    local Character = Tool.Parent --script > Tool > Character
    if Hit.Parent and Debounce == false then --Checking if there's a Hit.Parent (Or player character in this instance) & if the debounce is false
        Debounce = true --Setting the debounce to true to ensure that the function will run once
        local Yeet = Instance.new("BodyVelocity") --This is gonna force the player backwards
        Yeet.Velocity = Character.HumanoidRootPart.CFrame.LookVector * 50
        Yeet.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
        game.Debris:AddItem(Yeet, 0.5) --Setting a timer for the Velocity once it gets destroyed
        wait(5)
        Debounce = false --Setting the debounce back to false
    end
end

Tool.Touched:Connect(HitDetection)
2 Likes

Thank you for your reply, I will surely try that!

Thank you for replying! I have a few questions about this script. Firstly, does it reset after it’s finished? By that I mean once the script ends, does it destroy the BodyVelocity and let the player move again because I don’t want the player to be lying down on the floor the whole game. Also, how hard does it push the player off? If it throws them too far, they might fall off the map and that would be unfair for them. Thank you for the help!

Specifying the character before the tool is equipped is not gonna work, you’re basically just assigning the identifier character to the player’s backpack.

1 Like

They would only fall off the map if they are at a point where whatever they’re facing is just empty space and not walls, they would also need to be close to the edge of the wall for it to actually reach that point and fall off the end since the velocity is removed after half a second.

1 Like

If that’s the case then it should be fine because the map has walls. Now, my only concern is getting the player back up after a few seconds. Thanks!

The player does not fall when a velocity is assigned unless they’re glitched into a wall or the ground at a really high velocity (they would fling at that point), which most likely won’t happen in your case. You can also FireClient on the player that got hit and change their humanoid state to Enum.HumanoidStateType.FallingDown to make them trip to give that effect if you’d like, it will automatically let them back up after a second.

Parent.Parent.Parent.Parent.Parent.Parent

Depends on how much force you’d want to exert the Velocity on the player, I believe you can also set the MaxForce to a high number as well but you’d need to experiment with that

AddItem() is basically just setting a certain time interval for the chosen variable, then destroyed it after that time interval has passed, if I were to put:

local Part = Instance.new("Part")
Part.Parent = workspace

game.Debris:AddItem(Part, 5)

The Part would last for 5 seconds, then afterwards be destroyed (Or parented to nil? Not certain)

1 Like

Oh ok then. So this basically just flings them away? Isn’t that going to cause some errors as people will be flinging each other from atop a hill and a fling might throw them over the walls. In most KOTH games, people become ragdoll for a few seconds and slide down the hill. If this is not possible then it’s ok. Thank you!

Oh then that’s perfect, thank you!

Not really a fling, it basically applies a ‘push’ if you will, and moves them in the way that you passed whatever Vector3 value to the Velocity property of the BodyVelocity itself. But like I said, if the player gets stuck inside the ground or a wall at a high speed, it will push them out of the wall and ‘fling’ them.

1 Like

Question, would using a BodyVelocity or BodyForce be better for knockback related weapons? I haven’t exactly figured out what the exact difference really is :thinking:

1 Like

A BodyVelocity exerts force constantly (constant velocity) on an object while going against gravity so it will continue going in the direction that you specified for the Velocity property at the rate of your MaxForce property. A BodyForce is basically a push using the magnitude and direction from the Force property of the BodyForce.

2 Likes

Thank you everyone! I tried the script and it works just fine, thanks a lot for your time and effort!