Why does this keep repeating the damage?
Asked by
8 years ago Edited 8 years ago
local = debounce
Player = script.Parent.Parent
c = Player.Character
Sword = Instance.new("Part")
Sword.Parent = c
SwordMesh = Instance.new("SpecialMesh")
SwordMesh.MeshId = "rbxassetid://432068544"
SwordMesh.Parent = Sword
Sword.CanCollide = false
w1 = Instance.new("Weld", c)
w1.Part0 = w1.Parent["Right Arm"]
w1.Part1 = Sword
w1.C1 = CFrame.fromEulerAnglesXYZ(1.5,0,1.4) *CFrame.new(0,1.2,2)
function onSliced(Target) --Changed the variable.
if debounce == false then
debounce = true
if Target.Parent:FindFirstChild("Humanoid") then --Locating Humanoid.
if game.Players:GetPlayerFromCharacter(Target.Parent) ~= Player then --Now that we confirmed it was a character model, compare it to if the player is the target.
Target.Parent.Humanoid.Health = Target.Parent.Humanoid.Health - 5.5 --Reduce health. ForceFields will not respect this method. I would recommend using function TakeDamage().
print("Hit")
wait(1)
debounce = false
end
end
end
Sword.Touched:connect(onSliced)
--It works fine but When My sword touches a humanoid It does damage multiple times I tried adding debounce but that just breaks the script any help?
this is how I added it(debounce)