Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Define the punch tool
- local punchTool = Instance.new("Tool")
- punchTool.Name = "Punch Tool"
- punchTool.RequiresHandle = false
- punchTool.Parent = game.Players.LocalPlayer.Backpack
- -- Define the punch function
- local function punch(player)
- -- Create a hitbox at the player's position
- local hitbox = Instance.new("Part")
- hitbox.Size = Vector3.new(3, 3, 3)
- hitbox.Transparency = 1
- hitbox.CanCollide = false
- hitbox.CFrame = player.Character.HumanoidRootPart.CFrame
- hitbox.Parent = game.Workspace
- -- Apply a force to all parts within the hitbox
- local parts = game.Workspace:GetPartsInPart(hitbox)
- for _, part in ipairs(parts) do
- local humanoid = part.Parent:FindFirstChildOfClass("Humanoid")
- if humanoid then
- local direction = (part.Position - hitbox.Position).Unit
- humanoid:TakeDamage(10)
- humanoid:ChangeState(Enum.HumanoidStateType.FallingDown)
- humanoid:AddImpulse(direction * 10000)
- end
- end
- -- Clean up the hitbox
- hitbox:Destroy()
- end
- -- Connect the punch function to the punch tool's equipped event
- punchTool.Equipped:Connect(function()
- punchTool.Activated:Connect(function()
- punch(game.Players.LocalPlayer)
- end)
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement