So I was developing a sword when I encountered a problem. When the sword is touched, nothing happens. But when activated then touch humanoid or a player, it damages it and I still suck at scripting so I didn’t really know what to do. Can someone give and explain an solution?
Here’s the script:
local Tool = script.Parent
local Anim = script.Attack
local Event = game.ReplicatedStorage.RemoteEvents.DmgTextChanngedEvent
local DmgValue = game.ReplicatedStorage.Values.SwordDmgValue
local DebounceTable = {}
local db = false
Tool.Activated:Connect(function()
if not db then
db = true
local RandomizeDmg = math.random(10,30)
DmgValue.Value = RandomizeDmg
Anim.AnimationId = "rbxassetid://10970733238"
local Humanoid = Tool.Parent:FindFirstChild("Humanoid")
local AnimTrack = Humanoid:LoadAnimation(Anim)
AnimTrack:Play()
wait(1)
db = false
end
script.Parent:WaitForChild("Handle").Touched:Connect(function(hit)
if hit.Parent then
if hit.Parent:FindFirstChild("Humanoid") then
if DebounceTable[hit.Parent] == true then return end
DebounceTable[hit.Parent] = true
if hit.Parent:FindFirstChild("Humanoid").Health <= 0 then
return
else
hit.Parent.Humanoid:TakeDamage(DmgValue.Value)
local char = Tool.Parent
local plr = game.Players:GetPlayerFromCharacter(char)
Event:FireClient(plr)
wait(1)
DebounceTable[hit.Parent] = nil
end
end
end
end)
end)