Hi! I’m making an ability that does a heavy punch. My problem is that when the arm touches the other player it doesn’t work. But sometimes there is a small chance for it to work.
Script
local touched = false
game.ReplicatedStorage.AbilityUse.OnServerEvent:Connect(function(plr)
plr.Character.Humanoid.WalkSpeed = 4
plr.Character.Humanoid.JumpHeight = 0
local CombatHeavy = plr.PlayerGui.Animations:WaitForChild("CombatHeavy")
local CombatHeavyAnim = plr.Character.Humanoid:LoadAnimation(CombatHeavy)
CombatHeavyAnim:Play()
wait(0.5)
plr.Character["Right Arm"].CanTouch = true
plr.Character["Right Arm"].Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent ~= plr.Character then
if hit.Parent.Humanoid.Health > 0 then
if not touched then
touched = true
plr.Character["Right Arm"].CanTouch = false
local PunchSFX = Instance.new("Sound")
PunchSFX.Name = "CombatHeavy"
PunchSFX.RollOffMaxDistance = 150
PunchSFX.RollOffMinDistance = 1
PunchSFX.RollOffMode = Enum.RollOffMode.Linear
PunchSFX.Parent = plr.Character.HumanoidRootPart
PunchSFX.SoundId = "rbxassetid://7346569653"
PunchSFX:Play()
local target = hit.Parent
local joints = target:GetDescendants()
target.Humanoid.Health = target.Humanoid.Health - 18
target.HumanoidRootPart.Velocity = plr.Character.HumanoidRootPart.CFrame.LookVector * 300 + Vector3.new(0,300,0)
for _,joint in pairs(joints) do
if joint:isA("Motor6D") then
local socket = Instance.new("BallSocketConstraint")
local att0 = Instance.new("Attachment")
local att1 = Instance.new("Attachment")
print(joint)
target.Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
target.Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
target.Humanoid.AutoRotate = false
--target.Humanoid.PlatformStand = true
--target.Humanoid.WalkSpeed = 0
--target.Humanoid.JumpPower = 0
att0.Name = "Att0"
att1.Name = "Att1"
att0.CFrame = joint.C0
att1.CFrame = joint.C1
att0.Parent = joint.Part0
att1.Parent = joint.Part1
socket.Parent = joint.Part0
socket.Attachment0 = att0
socket.Attachment1 = att1
att0.Name = "Att0"
att1.Name = "Att1"
socket.LimitsEnabled = true
socket.TwistLimitsEnabled = true
--wait(0.2)
--wait(2)
joint.Enabled = false
end
end
if hit.Parent.Humanoid.Health > 0 then
if target.Name ~= "Dummy3" then
target.Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
target.Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, true)
target.Humanoid.AutoRotate = true
target.Humanoid.WalkSpeed = 26
target.Humanoid.JumpPower = 7.5
for _,joint2nd in pairs(joints) do
if joint2nd:isA("Motor6D") then
joint2nd.Enabled = true
end
end
for _, child in pairs(target:GetDescendants()) do
if child.Name == "Att0" or child.Name == "Att1" or child:IsA("BallSocketConstraint") then
child:Destroy()
end
end
end
end
end
end
wait(2)
plr.Character.Humanoid.WalkSpeed = 26
plr.Character.Humanoid.JumpHeight = 7.2
touched = false
wait(2)
end
end)
end)
This is the code that doesn’t work:
plr.Character["Right Arm"].Touched:Connect(function(hit)
Any help appreciated.