How to create a punch tool

so i wanna create a punch tool and evertyime u click an anim plays and a part spawns for 0.1 second, and anyone inside the part gets damaged the punch tool users Strength leaderstat value, i alr made one but it doesnt change value when u get more strength heres my script:

local player = game.Players.LocalPlayer
local tool = script.Parent
local cd = false
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://72977696799369"

local screenGui = player:WaitForChild("PlayerGui"):WaitForChild("StrengthGui")
local textLabel = screenGui:FindFirstChild("StrengthAdded")

local function onTouched(part, player)
	local leaderstats = player:FindFirstChild("leaderstats")
	local strength = leaderstats:FindFirstChild("Endurance")
	local otherPlayer = game.Players:GetPlayerFromCharacter(part.Parent)
	if otherPlayer and otherPlayer ~= player then
		local otherHumanoid = otherPlayer.Character:FindFirstChildOfClass("Humanoid")
		if otherHumanoid then
			otherHumanoid:TakeDamage(strength.Value)
		end
	end
end

tool.Activated:Connect(function()
	if not cd then
		cd = true
		local LoadedAnimtion = player.Character:WaitForChild("Humanoid"):LoadAnimation(animation)
		LoadedAnimtion.Priority = Enum.AnimationPriority.Action
		LoadedAnimtion:Play()
		local punchPart = Instance.new("Part")
		punchPart.Size = Vector3.new(5, 5, 5)
		punchPart.Transparency = 0.5
		punchPart.Anchored = true
		punchPart.CanCollide = false
		punchPart.CFrame = player.Character.PrimaryPart.CFrame * CFrame.new(0, 0, -5)
		punchPart.Parent = workspace
		punchPart.Touched:Connect(onTouched)
		task.wait(0.01)
		cd = false
		punchPart:Destroy()
	end
end)

1 Like

Make sure the Requires Handle on the tool is disabled, b/c if it’s enabled then the tool won’t activate with a handle.

2 Likes

I believe the issue here is that the value of the strength from the leaderstats doesnt change

1 Like

if @HeCatchThose solution didn’t work, my suggestion is to do smth like this:

local player = game.Players.LocalPlayer
local tool = script.Parent
local cd = false
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://72977696799369"

local screenGui = player:WaitForChild("PlayerGui"):WaitForChild("StrengthGui")
local textLabel = screenGui:FindFirstChild("StrengthAdded")

local function onTouched(part, player)
	local leaderstats = player:FindFirstChild("leaderstats")
	local strength = leaderstats:FindFirstChild("Endurance")
	local otherPlayer = game.Players:GetPlayerFromCharacter(part.Parent)
	if otherPlayer and otherPlayer ~= player then
		local otherHumanoid = otherPlayer.Character:FindFirstChildOfClass("Humanoid")
		if otherHumanoid then
			otherHumanoid:TakeDamage(strength.Value)
		end
	end
end

local function Punch()
	if not cd then
		cd = true
		local LoadedAnimtion = player.Character:WaitForChild("Humanoid"):LoadAnimation(animation)
		LoadedAnimtion.Priority = Enum.AnimationPriority.Action
		LoadedAnimtion:Play()
		local punchPart = Instance.new("Part")
		punchPart.Size = Vector3.new(5, 5, 5)
		punchPart.Transparency = 0.5
		punchPart.Anchored = true
		punchPart.CanCollide = false
		punchPart.CFrame = player.Character.PrimaryPart.CFrame * CFrame.new(0, 0, -5)
		punchPart.Parent = workspace
		punchPart.Touched:Connect(onTouched)
		task.wait(0.01)
		cd = false
		punchPart:Destroy()
	end
end

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(input, gp)
	if gp then return end

	if script.Parent.Parent == player.Character then
		if input.UserInputType == Enum.UserInputType.MouseButton1 then
			Punch()
		end

		if UserInputService.TouchEnabled and input.UserInputType == Enum.UserInputType.Touch then
			Punch()
		end
	end
end)

Hi, I tried this code, in a tool, and activated it, and nothing happens… the punch part does not get created…

(commented out screengui and textlabel…

1 Like

Hello, thank you for testing the code and figuring out if it worked or not, I rushed this script without testing

Are u able to test my script? (Notice that theres leaderstats too)

i tested it, the part spawns but deals no damage to players even if i have 1000 strength

for me it spawns, maybe it didnt work bcuz it couldnt find and play anim bcuz for u its sanitized. also this is not related but what is that avatar bro

sry guys if i didnt respond, u guys responded at midnight for me

it deals damages to players, are u testing on a dummy? if yes i will edit the script.

i was testing on my alt account both in a team test, but if u can i just want it to find a humanoid so i can test on a dummy too

local player = game.Players.LocalPlayer
local tool = script.Parent
local cd = false
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://72977696799369"

local screenGui = player:WaitForChild("PlayerGui"):WaitForChild("StrengthGui")
local textLabel = screenGui:FindFirstChild("StrengthAdded")

local function onTouched(part: BasePart)
	if part and part.Parent:FindFirstChild("Humanoid") then
		local leaderstats = player:FindFirstChild("leaderstats")
		local strength = leaderstats:FindFirstChild("Endurance")
		
		if not part:IsDescendantOf(player.Character) then
			local otherHumanoid = part.Parent:FindFirstChild("Humanoid")
			if otherHumanoid then
				otherHumanoid:TakeDamage(strength.Value)
			end
		end
	end
end

local function Punch()
	if not cd then
		cd = true
		local LoadedAnimtion = player.Character:WaitForChild("Humanoid"):LoadAnimation(animation)
		LoadedAnimtion.Priority = Enum.AnimationPriority.Action
		LoadedAnimtion:Play()
		local punchPart = Instance.new("Part")
		punchPart.Size = Vector3.new(5, 5, 5)
		punchPart.Transparency = 0.5
		punchPart.Anchored = true
		punchPart.CanCollide = false
		punchPart.CFrame = player.Character.PrimaryPart.CFrame * CFrame.new(0, 0, -5)
		punchPart.Parent = workspace
		punchPart.Touched:Connect(onTouched)
		task.wait(0.01)
		cd = false
		punchPart:Destroy()
	end
end

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(input, gp)
	if gp then return end

	if script.Parent.Parent == player.Character then
		if input.UserInputType == Enum.UserInputType.MouseButton1 then
			Punch()
		end

		if UserInputService.TouchEnabled and input.UserInputType == Enum.UserInputType.Touch then
			Punch()
		end
	end
end)

is it checking the strength of who its hitting or the person who is using the tool

checks the strength of the one using the tool.

um it deals damage but it deals like 5x more than my actual strength, when i kill it and check the. humanoid, it says the health is -6000, when i only have 1075 strength, then i set the rigs max health and health to 1076, 1 more than my strength, and kill it, i check its health and its -4000

well that happens cuz its touching alot of parts, try this:

local player = game.Players.LocalPlayer
local tool = script.Parent
local cd = false
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://72977696799369"

local screenGui = player:WaitForChild("PlayerGui"):WaitForChild("StrengthGui")
local textLabel = screenGui:FindFirstChild("StrengthAdded")

local function onTouched(part: BasePart)
	if part and part.Parent:FindFirstChild("Humanoid") then
		local leaderstats = player:FindFirstChild("leaderstats")
		local strength = leaderstats:FindFirstChild("Endurance")
		
		if not part:IsDescendantOf(player.Character) then
			local otherHumanoid = part.Parent:FindFirstChild("Humanoid")
			if otherHumanoid then
				otherHumanoid:TakeDamage(strength.Value)
			end
		end
	end
end

local function Punch()
	if not cd then
		cd = true
		local LoadedAnimtion = player.Character:WaitForChild("Humanoid"):LoadAnimation(animation)
		LoadedAnimtion.Priority = Enum.AnimationPriority.Action
		LoadedAnimtion:Play()
		local punchPart = Instance.new("Part")
		punchPart.Size = Vector3.new(5, 5, 5)
		punchPart.Transparency = 0.5
		punchPart.Anchored = true
		punchPart.CanCollide = false
		punchPart.CFrame = player.Character.PrimaryPart.CFrame * CFrame.new(0, 0, -5)
		punchPart.Parent = workspace
		punchPart.Touched:Once(onTouched)
		task.wait(0.01)
		cd = false
		punchPart:Destroy()
	end
end

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(input, gp)
	if gp then return end

	if script.Parent.Parent == player.Character then
		if input.UserInputType == Enum.UserInputType.MouseButton1 then
			Punch()
		end

		if UserInputService.TouchEnabled and input.UserInputType == Enum.UserInputType.Touch then
			Punch()
		end
	end
end)
1 Like

um, i dont see a difference in the script?

Changed the :connect, to :once, to fire once when the part is touched, not multiple times.

, oh it works thx a lot

char limit

1 Like