I am working on a survival game and players cant kill each other I want them to work together to kill monsters to progress through the game it works fine but I just want the damage without swinging bug gone.
– My current code –
local active = false
local hitting = false
local swordDamage = 15
script.Parent.Sword.Touched:Connect(function(hit)
if hit.Parent:findFirstChild("Humanoid") then
local name = hit.Parent.Name
if not game.Players:FindFirstChild(name) then
if active == false and hitting == false then
if hit.Parent:findFirstChild("ForceField") then
if hit.Parent.ForceField.Visible == true then
return
end
end
hitting = true
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - swordDamage
local sound = Instance.new("Sound",hit.Parent)
sound.PlayOnRemove = true
sound.SoundId = "rbxassetid://4935128724"
sound.Volume = 1
sound.TimePosition = 1
sound:Destroy()
wait(.5)
hitting = false
end
end
end
end)