I’m testing out this damage script that I used a while back and for some reason, when a new tool is equipped while the player had the weapon equipped, it stops doing damage after you re-equip it. Why does this happen?
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
local damage = 10
local enabledToDamage = true
function blow(hit)
if not enabledToDamage then
return
end
enabledToDamage = false
if not hit.Parent then
enabledToDamage = true
return
end
local humanoid = hit.Parent:FindFirstChild("Humanoid")
local vCharacter = Tool.Parent
local vPlayer = Players:GetPlayerFromCharacter(vCharacter)
local hum = vCharacter:FindFirstChild("Humanoid")
if humanoid and humanoid ~= hum and hum then
local rightArm = vCharacter:FindFirstChild("Right Arm")
if rightArm then
local joint = rightArm:FindFirstChild("RightGrip")
if joint and (joint.Part0 == Handle or joint.Part1 == Handle) then
print("Valid hit on another player")
tagHumanoid(humanoid, vPlayer)
humanoid:TakeDamage(damage)
wait(1)
untagHumanoid(humanoid)
else
enabledToDamage = true
end
else
enabledToDamage = true
end
else
enabledToDamage = true
end
end
function tagHumanoid(humanoid, player)
local creatorTag = Instance.new("ObjectValue")
creatorTag.Value = player
creatorTag.Name = "creator"
creatorTag.Parent = humanoid
print("Tagged humanoid:", humanoid)
end
function untagHumanoid(humanoid)
if humanoid then
local tag = humanoid:FindFirstChild("creator")
if tag then
tag.Parent = nil
print("Untagged humanoid:", humanoid)
end
end
end
function onActivated()
local character = Tool.Parent
local humanoid = character:FindFirstChild("Humanoid")
if not Tool.Enabled then
print("Tool not enabled")
return
end
Tool.Enabled = false
if not humanoid then
print("Humanoid not found in character")
return
end
print("Tool activated")
enabledToDamage = true
wait(0.5)
enabledToDamage = false
Tool.Enabled = true
end
function onEquipped()
wait(1/3)
print("Tool equipped")
end
Tool.Enabled = true
Tool.Equipped:Connect(onEquipped)
Tool.Activated:Connect(onActivated)
Handle.Touched:Connect(blow)
Hello! Are any of your first return statements firing when you re-equip the item? I saw that you have print statements everywhere except there and it might outline the issue better if we know which is giving the return, if either.
Hello, still looking through this, not sure what you mean by a local server though. Sorry. Also, when you click, is the tool activating every time and the blow function the only thing not workign?
Oh ok thank you very much for making that more apparent.
I am thinking it might be switching priority to touch your characters arm instead of the person you are trying to hit. You might want to attach another part to your tool that hits the other player and avoids your character so that the touch isnt fighting with priorities over who it should be touching.
Another method is raycasting but that would require a bit of a re write and blah blah.
Bottom line I think its just interfering because from what I am seeing you have to exclude the players arm but it might be considering the players arm and only doing the exclusion case instead of the inclusion case with the other players character.
Hopefully this helps or is on track, again I realyl apologize if I am not making sense I have been fried lately because I am overworking myselfLol.