Highlight Script Not working

I am trying to make a highlight script that makes an NPC that you have hit with your sword gradually red and then slowly reverts back. I’ve never done this and my code is not working. :angst:

Script:

local function light(hrp) --Highlights the hrp
	local highlight = hrp.Highlight
	for i = 0,600,1 do
		highlight.FillTransparency.Value -= .01
	end
	for i = 0,600,1 do
		highlight.FillTransparency.Value += .01
	end
end

Error:

attempt to index nil with 'Highlight'

the error says that the humanoidrootpart your passing is nil. and you didn’t add a wait in the for loops

1 Like

How would I fix this? I am a little confused.

1 Like

esentially, you’re passing nil as the humanoidrootpart. to fix this, i’d need to see more of the script that shows how you’re passing the humanoidrootpart to the function

1 Like
tool:WaitForChild("Handle").Touched:Connect(function(hit)
	if debounce then return end
	-- Will run if the item that touched the handle has a Humanoid
	if hit.Parent:FindFirstChild("Humanoid") then
		local humanoid = hit.Parent.Humanoid
		local hrp = hit.Parent.HumanoidRootPart

Is this good?

print hrp in that script and tell me what it shows in the output.

by the way, i’m not sure if a highlight even shows in the humanoidrootpart, correct me if i’m wrong though

It just says

HumanoidRootPart
1 Like

could you show the part of the script where you’re calling the function

1 Like

It is very simple.

		light()

you’re not passing the hrp variable at all
do this:

light(hrp)

but, i’m not sure if the highlight will show in the humanoidrootpart

attempt to index number with 'Value'

I think this has to do with the hrp. I will try using a part.

I still got the same output :frowning:

did you use this light(hrp) because you sent nothing in the calling of the function

This time I changed it to a part but yes.

what do you mean by part? i’m confused on what you mean by “using” a part

I just copy and pasted the hrp, deleted everything inside except for the highlight, and I renamed it to glow.

you shouldn’t do that, just add the highlight to the model of the player. the model of the player is just the character of the player

Same error. :frowning: I think this might be the issue but I don’t know what’s wrong.

local function light(glow) --Highlights the hrp
	for i = 0,600,1 do
		glow.FillTransparency.Value -= .01
		task.wait(0.005)
	end
	for i = 0,600,1 do
		glow.FillTransparency.Value += .01
		task.wait(0.005)
	end
end