This script is supposed to hurt player when the weapon is swung but after swinging the weapon is still able to kill so I tried using connection / disconnect() but now it doesn’t work at all. Could someone please help me?
-- Server Script
local remoteEvent = game.ReplicatedStorage.DamageRM
local coolDown = true
local connection
connection = remoteEvent.OnServerEvent:Connect(function(plr, hit)
hit.Parent.Humanoid.Health = 0
end)
task.wait(2)
connection:Disconnect()
-- Local Script
local tool = script.Parent.Parent
local myPillowModel = game.Players.LocalPlayer.Character.PillowModel
local damageRM = game.ReplicatedStorage:WaitForChild("DamageRM")
local canDmg = true
local soundService = game:GetService("SoundService")
local humanoid = game.Players.LocalPlayer.Character.Humanoid
--IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
local HitAnimation = Instance.new("Animation")
HitAnimation.AnimationId = "rbxassetid://15910080700"
local HitAnimationTrack = humanoid:LoadAnimation(HitAnimation)
-- IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
local toolRunAnimation = Instance.new("Animation")
toolRunAnimation.AnimationId = "rbxassetid://15910039503"
local toolAnimationTrack = humanoid:LoadAnimation(toolRunAnimation)
local sound = Instance.new("Sound", tool)
sound.SoundId = "rbxassetid://9120386436"
tool.Equipped:Connect(function()
myPillowModel.Transparency = 1
toolAnimationTrack:Play()
end)
tool.Unequipped:Connect(function()
myPillowModel.Transparency = 0
toolAnimationTrack:Stop()
end)
tool.Activated:Connect(function()
if canDmg then
canDmg = false
toolAnimationTrack:Stop()
HitAnimationTrack:Play()
tool.Handle.Hitbox.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid")then
damageRM:FireServer(hit)
end
end)
task.wait(1)
toolAnimationTrack:Play()
task.wait(2)
canDmg = true
else
soundService:PlayLocalSound(sound)
end
end)