I'm adding the combat/knockback system.
I made this script:
function punched()
script.Parent.Parent:WaitForChild("RightHand").Touched:Connect(function(hit)
if hit.Parent.Humanoid ~= nil then
local vf = Instance.new("VectorForce")
local at = Instance.new("Attachment")
vf.Parent = hit.Parent:WaitForChild("HumanoidRootPart")
vf.Force =
script.Parent.Parent:WaitForChild("HumanoidRootPart").CFrame.LookVector * 500
at.Parent = vf.Parent
vf.Attachment0 = at
vf.RelativeTo = Enum.ActuatorRelativeTo.World
hit.Parent.Humanoid.PlatformStand = true
wait(0.1)
hit.Parent.Humanoid.PlatformStand = false
vf:Destroy()
at:Destroy()
script.Parent.ActivateScript.Enabled = true
end
end)
end
script.Parent.Punched.Event:Connect(punched)
And here is the 2nd script:
local canpunch = true
function activated()
if canpunch == true then
canpunch = false
script.Parent.Parent:WaitForChild("RightHand").CanTouch = false
script.Parent.Punched:Fire()
script.Enabled = false
wait(0.5)
canpunch = true
script.Parent.Parent:WaitForChild("RightHand").CanTouch = true
end
end
script.Parent.Activated:Connect(activated)
I also added a BindableEvent called Punched
But when I activate the tool it first works good, but after, when I touch a character even without activating the tool it still knocks the character back but with much more force.
How to fix this?