I have this melee weapon script and It was working a couple days ago but it no longer works and I have tried to fix it even with some debounces and it still seems to do the same thing.
It does damage multiple times at a set interval so like 1 time every 1 second
Heres the code
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ResourceGatheredEvent = ReplicatedStorage:WaitForChild("ResourceGathered")
local AttackedDebounce = false
local ResourceTable = {"TreeType1"; "ClothType1"; "StoneType1"; "MetalType1"; "SulfurType1"; "CharcoalType1"}
local PlayerDamage = math.random(15,20)
local ResourceDamage = math.random(10,15)
local HarvestAmount = script.Parent.HarvestAmount
-- Humanoid attacked
function AttackedPlayer(Hit)
local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
local Character = script.Parent.Parent
local Player = game.Players:playerFromCharacter(Character)
local Hum = Character:findFirstChild("Humanoid")
if Humanoid ~= nil and Humanoid ~= Hum and Hum ~= nil then
-- final check, make sure sword is in-hand
TagHumanoid(Humanoid, Player)
Humanoid:TakeDamage(PlayerDamage)
wait(.5)
UntagHumanoid(Humanoid)
end
end
function TagHumanoid(Humanoid, Player)
local Creator_Tag = Instance.new("ObjectValue")
Creator_Tag.Value = Player
Creator_Tag.Name = "Creator"
Creator_Tag.Parent = Humanoid
end
function UntagHumanoid(Humanoid)
if Humanoid ~= nil then
local Tag = Humanoid:FindFirstChild("Creator")
if Tag ~= nil then
Tag.Parent = nil
end
end
end
-- Resource attacked
function AttackedResource(Hit)
local Player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
local Health = Hit.Parent:FindFirstChild("Health")
local Object = Hit.Parent
local ObjectName = Hit.Parent
TagResource(Object, ObjectName)
Health.Value = Health.Value - ResourceDamage
if Hit.Parent.Health.Value >= 0 and Hit.Parent.Enabled.Value == true then
ResourceGatheredEvent:FireClient(Player)
ReplicatedStorage.PlayerStats[Player.Name][Object.ResourceType.Value].Value = ReplicatedStorage.PlayerStats[Player.Name][Object.ResourceType.Value].Value + HarvestAmount.Value
end
wait(.5)
UntagHumanoid(Object)
end
function TagResource(Object, ObjectName)
local Creator_Tag = Instance.new("ObjectValue")
Creator_Tag.Value = ObjectName
Creator_Tag.Name = "Creator"
Creator_Tag.Parent = Object
end
function UntagResource(Object)
if Object ~= nil then
local Tag = Object:FindFirstChild("Creator")
if Tag ~= nil then
Tag.Parent = nil
end
end
end
-- Fires damage events when object is touched
script.Parent.HitBox.Touched:Connect(function(Hit)
if AttackedDebounce == false then
AttackedDebounce = true
if script.Parent.CanAttack.Value == true then
script.Parent.CanAttack.Value = false
for i,v in pairs(ResourceTable) do
if Hit.Parent.Name == v then
AttackedResource(Hit)
else
AttackedPlayer(Hit)
end
end
end
wait(.5)
AttackedDebounce = false
end
end)
I know its a script not a local script, I understand that, but that is not the problem.
Thank you for your time, also here is a gif of whats happening
https://gyazo.com/faf16d8006df8d84098bdd40696e8dd0
Sorry for low quality Gyazo isnt the best XD you might have to full screen it, but you can see how it does damage even when I am far away from the dummy.
