How Do I Make This Script Only Work If The Humanoid Touches The PunchBag In Workspace

local debounce = false
local plr = game.Players.LocalPlayer
local PunchBag = workspace.PunchBag

script.Parent.MouseButton1Click:Connect(function()
if not debounce then
debounce = true
plr.leaderstats.Speed.Value = plr.leaderstats.Speed.Value + 5
print(“button was pressed!”)
wait(2)
debounce = false
end
end)

I’m assuming you want the humanoid to touch the physical part?

script.Parent.Touched:Connect(function(hit)
if hitParent:FindFirstChildWhichIsA("Humanoid") then
local debounce
if not debounce then
debounce = true
plr.leaderstats.Speed.Value = plr.leaderstats.Speed.Value + 5
print(“button was pressed!”)
wait(2)
debounce = false
end
end)
1 Like

when u click the textbutton it plays a punching animation and when the hand touches the part i need it to give speed

local debounce = false
local plr = game.Players.LocalPlayer
local PunchBag = workspace.PunchBag

script.Parent.MouseButton1Click:Connect(function()
if not debounce then
debounce = true
-- Play your animation here --

PunchBag.Touched:Connect(function(hit)
if hit.Name == "RightHand" or "RightLowerArm" or "RightUpperArm" or "RightArm" or "LeftHand" or "LeftLowerArm" or "LeftUpperArm" or "LeftArm" then
plr.leaderstats.Speed.Value = plr.leaderstats.Speed.Value + 5
print(“button was pressed!”)
wait(2)
debounce = false
end
end
end)
end)