-
What do you want to achieve? Keep it simple and clear!
I am trying to make a sword damage a player. -
What is the issue? Include screenshots / videos if possible!
The.Touched
function only will run twice then it won’t do anything anymore. TheCanTouch
property is set toTrue
and it doesn’t get changed. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I am using print statements, that is how I know that it only runs twice.
Code
--////////////////Config///////////////--
local Damage = 20 --Change this amout to the ammount of dammage you want your weapon to deal 100 is insta kill
--/////////////////////////////////////--
local SwingEvent = game.ReplicatedStorage.SwingEvent
local Character = script.Parent.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local Blade = script.Parent.Sword
local CanHit = false
SwingEvent.OnServerEvent:Connect(function(player, Action)
if Action == "Start" then
CanHit = true
else
CanHit = false
end
end)
Blade.Touched:Connect(function(Part)
print("Touched")
if Part.Name ~= "Scutum" and Part.Parent:FindFirstChild("Humanoid") and CanHit then
CanHit = false
print("Is a Body Part")
script.Parent.Humanoid:TakeDamage(Damage)
script.Parent.BodyHit:Play()
elseif Part.Name == "Scutum" and CanHit then
CanHit = false
print("Is a Shield")
script.Parent.WoodShieldHit:Play()
end
end)