Basically, I made a script that plays an animation for a tool, and if the hitbox in the tool hits a player, the hit player takes 10 damage and a remote event fires (has nothing to do with the issue i believe)
My script: (i know i could remove some functions and make it way shorter, but im happy as long as it works)
local alreadytouched = false
local cooldowntime = 1.5
local enabled = false
script.Parent.Equipped:Connect(function()
local plr = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
local db = plr:FindFirstChild("ItemCooldown")
print(plr.Name)
script.Parent.Activated:Connect(function()
if db.Value == false then
db.Value = true
local anim = script.Parent.Animation
local anim2 = plr.Character:WaitForChild("Humanoid").Animator:LoadAnimation(anim)
script.Parent.BodyAttach.Sound:Play()
wait(0.1)
anim2:Play()
wait(0.5)
alreadytouched = true
script.Parent.Hitbox.Touched:Connect(function(hit)
if alreadytouched == true then
enabled = true
local hmn = game.Players:GetPlayerFromCharacter(hit.Parent)
if hmn then
if enabled == true then
hmn.Character:FindFirstChild("Humanoid"):TakeDamage(11)
game.ReplicatedStorage.RemoteEvents.PlrPie:FireClient(hmn)
alreadytouched = false
plr:WaitForChild("leaderstats").SmashPoints.Value += 1
elseif enabled == false then
return
end
else
wait(0.1)
end
end
end)
anim2.Ended:Wait()
wait(1.5)
db.Value = false
return
elseif db.Value == true then
wait(1.5)
end
end)
script.Parent.Unequipped:Connect(function()
enabled = false
alreadytouched = false
return
end)
end)