For some reason, the TakeDamage() feature for Humanoid didn’t work for me. Idk why. Imma need some help here really quick.
Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Events = ReplicatedStorage:WaitForChild("Events")
local Animations = ReplicatedStorage:WaitForChild("Animations")
local sword = script.Parent.Parent
local model = sword.Model
local handle = sword.Handle
local function OnTouch(part)
script.Disabled = true
local character = part.Parent
local humanoid = character:FindFirstChild("Humanoid")
local track = humanoid:LoadAnimation(Animations:WaitForChild("damaged"))
if track.Looped ~= false then
track.Looped = false
end
track:Play()
humanoid:TakeDamage(20)
print("damage")
end
model.Touched:Connect(OnTouch)
Idk what else to do. I tried humanoid.Health = humanoid.Health - 20 but still doesn’t work. I also test it on a NPC character(default Dummy rig). Maybe you can help?
It looks like you disable the script when you call OnTouch()? Im not sure what that’s for, but it seems like that would make the script not work at all. Try removing that and see what happens.
local RS = game:GetService("ReplicatedStorage")
local Events = RS:WaitForChild("Events")
local Animations = RS:WaitForChild("Animations")
local DamagedAnim = Animations:WaitForChild("damaged")
local sword = script.Parent.Parent
local model = sword.Model
local handle = sword.Handle
local Debounce = false
local function OnTouch(Hit)
if Debounce then
return
end
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if Player then
Debounce = true
local Character = Player.Character
local Humanoid = Character.Humanoid
local DamagedTrack = Humanoid:LoadAnimation(DamagedAnim)
DamagedTrack.Looped = false
DamagedTrack:Play()
Humanoid:TakeDamage(20)
end
task.wait(2)
Debounce = false
end
handle.Touched:Connect(OnTouch)
Is “model” an actual Model instance? Because models do not have access to the .Touched event, instead you could use the BasePart instance named “Handle”. Also you shouldn’t disable the script mid-execution, you should be making use of a debounce instead, as I have done above.