Why is the red death effect not appearing when being damaged by this tool?

Achieve

I am attempting to achieve the red death effect when being damaged by this tool.

Issue

The issue is quite simple, it will not appear. No matter what I do, it will not appear.

Explanation

When I state the red death effect, this is what I mean. The red effect around the screen.

The Script

This is a long script, brace yourself.

--[Wrestling Clean Edition By TerryMichaelBrunk,Samaclub & MillerrIAm]--
----------------[Variables]----------------
local r = game:service("RunService")
local sword = script.Parent.Handle
local Tool = script.Parent
local plr = game.Players
local GUIFolder = script.Parent.GUIs
--[GUI Names]--
local GUIs = {"BrokenGUI","PlayerDelagGUI"}
--[Values]--
local damage = 0
local slash_damage = .5
local lunge_damage = 2.8
local debounce = false
----------------[Main Script]----------------
--[Blow Function]--
function blow(hit)
	if not debounce then
		debounce = true
		print("Running")
		local humanoid = hit.Parent:findFirstChild("Humanoid")
		local vCharacter = Tool.Parent
		local vPlayer = game.Players:playerFromCharacter(vCharacter)
		local hum = vCharacter:findFirstChild("Humanoid")
		if humanoid~=nil and humanoid ~= hum and hum ~= nil then
			humanoid.Health = humanoid.Health - damage
		end
		game:GetService("RunService").Stepped:Wait()
		debounce = false
		tagHumanoid(humanoid, vPlayer)
		wait(1)
		untagHumanoid(humanoid)
	end
end
--[Tag Humanoid Function]--
function tagHumanoid(humanoid, player)
	local creator_tag = Instance.new("ObjectValue")
	creator_tag.Value = player
	creator_tag.Name = "creator"
	creator_tag.Parent = humanoid
end
--[Untag Humanoid Function]--
function untagHumanoid(humanoid)
	if humanoid ~= nil then
		local tag = humanoid:findFirstChild("creator")
		if tag ~= nil then
			tag.Parent = nil
		end
	end
end
--[Attack Function]--
function attack()
	damage = slash_damage
	local anim = Instance.new("StringValue")
	anim.Name = "toolanim"
	anim.Value = "Slash"
	anim.Parent = Tool
end
--[Lunge Function]--
function lunge()
	damage = lunge_damage
	local anim = Instance.new("StringValue")
	anim.Name = "toolanim"
	anim.Value = "Lunge"
	anim.Parent = Tool
	local force = Instance.new("BodyVelocity")
	force.velocity = Vector3.new(0,10,0)
	force.maxForce = Vector3.new(0,0,0)	
	force.Parent = Tool.Parent.Torso
	wait(.25)
	swordOut()
	wait(.25)
	force.Parent = nil
	wait(.5)
	swordUp()
	damage = slash_damage
end
--[Sword Up Function]--
function swordUp()
	Tool.Handle.CanCollide = false
	Tool.GripForward = Vector3.new(-1,0,0)
	Tool.GripRight = Vector3.new(0,1,0)
	Tool.GripUp = Vector3.new(0,0,1)
	Tool.Handle.CanCollide = true
end
--[Sword Out Function]--
function swordOut()
	Tool.Handle.CanCollide = false
	Tool.GripForward = Vector3.new(0,0,1)
	Tool.GripRight = Vector3.new(0,-1,0)
	Tool.GripUp = Vector3.new(-1,0,0)
	Tool.Handle.CanCollide = true
end
--[Tool Function]--
Tool.Enabled = true
local last_attack = 0
function onActivated()
	if not Tool.Enabled then
		return
	end
	Tool.Enabled = false
	local character = Tool.Parent;
	local humanoid = character.Humanoid
	if humanoid == nil then
		return 
	end
	local t = r.Stepped:wait()
	if (t - last_attack < .2) then
		lunge()
	else
		attack()
	end
	last_attack = t
	Tool.Enabled = true
end
--[GUI Give Function]--
script.Parent.Equipped:Connect(function()
	for i,GUIName in pairs(GUIs) do
		if not plr[script.Parent.Parent.Name].PlayerGui:FindFirstChild(GUIName) then
			GUIFolder[GUIName]:Clone().Parent = plr[script.Parent.Parent.Name].PlayerGui
		end
	end
end)
--[GUI Remove Function]--
script.Parent.Unequipped:Connect(function()
	for i,GUIName in pairs(GUIs) do
		if plr[script.Parent.Parent.Parent.Name].PlayerGui:FindFirstChild(GUIName) then
			plr[script.Parent.Parent.Parent.Name].PlayerGui[GUIName]:Destroy()
		end
	end
end)
--[Activation]--
script.Parent.Activated:connect(onActivated)
sword.Touched:Connect(function(hit)
	blow(hit)
end)

Side Note

I also realized that when you’re using a sword, the red death effect or the damage effect doesn’t appear either.

Thank you to anyone who helps me with this issue.

3 Likes

I just want to say that game:service should be replaced with game:GetService() and :connect() is deprecated (as I’ve read.) If this is a LocalScript, you’re going to want to fire to the server to deal the damage through a remote event, since the damage on the client in this script wouldn’t be replicated to other players. That’s why the damage wouldn’t appear to other players. As for the death effect, you’re going to want to fire back to the client to show the GUI. This is just a vague explanation but I suggest you look into something like it.

2 Likes

This is through a Server Script, I will look over your methods.
Although, this wouldn’t explain why swords do the exact same thing as the tool I’m working on.

1 Like

You may want to individually check each part of your damage function for any issues through printing. First, you may want to make a condition to print something if the part the sword touches is part of a model with a humanoid. This way, you’ll know the sword is detecting the enemy with the humanoid. If that’s all good, then put a print on your if statement with if humanoid ~= nil and humanoid ~= hum and hum ~= nil then to see if this condition is true.

function blow(hit)
	if not debounce then
		debounce = true
		print("Running")

		local humanoid = hit.Parent:findFirstChild("Humanoid")
                if humanoid then
                     print("humanoid detected")
                end
		local vCharacter = Tool.Parent
		local vPlayer = game.Players:playerFromCharacter(vCharacter)
		local hum = vCharacter:findFirstChild("Humanoid")
                if vCharacter and hum and vPlayer then
                     print("Player detected")
                end
		if humanoid~=nil and humanoid ~= hum and hum ~= nil then
                        print("taking damage")
			humanoid.Health = humanoid.Health - damage
		end
		game:GetService("RunService").Stepped:Wait()
		debounce = false
		tagHumanoid(humanoid, vPlayer)
		wait(1)
		untagHumanoid(humanoid)
	end
end
2 Likes

Everything printed successfully, I believe this is a bug, i’m about to report it in.

1 Like

The red effect only appears if the health loss is 5% or greater, if I remember correctly.

2 Likes

Is there a way to lower this by chance?

No. The threshold is in a CoreScript called TopbarConstants. You will need to create your own hurt overlay here. If you need the images for reference, they are as follows:

TopbarConstants.HURT_OVERLAY_IMAGE = "https://www.roblox.com/asset/?id=34854607"
TopbarConstants.HURT_OVERLAY_IMAGE_WHITE = "rbxasset://textures/ui/TopBar/WhiteOverlayAsset.png"

EDIT: There is technically a way to change it, but that’s relating to the Humanoid’s health values. The formula for calculating the threshold of health loss required for the Gui to show is 5% of the max health. For 100 health, 5 points need to be lost. For 200, it’s 10. So on.

4 Likes