Barbed Wire script randomly stops working

I have this barbed wire script inside of a part called “Metal”. Whenever a player touches the “Metal” part, they take damage. For some reason, it randomly stops working and I’m not sure why. In the output, I get this “error” (its in blue so it’s not?). Whenever I get this line, the code stops working. The line 11 and 18 that keeps showing up are the lines of code that find the person that touched it, finds their UpperTorso, and turns on/off the blood in there.

Code:

local ResetTime = 0.5      -- time it takes for the script to reset and damage players again
local isTouched = false  -- Declare debounce variable




function onTouched(hit)
	
if not isTouched then  -- Check that debounce variable is not true
isTouched = true  -- Set variable to true
hit.Parent.UpperTorso.Blood1.Rate = 100
script.Parent.Parent.Wood.HurtPlayer:Play()	
wait(0.5)
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 4
wait(ResetTime)  -- Wait for reset time duration
isTouched = false  -- Reset variable to false
wait(0.5)
hit.Parent.UpperTorso.Blood1.Rate = 0

end
end
script.Parent.Touched:connect(onTouched)

Error Image:

That’s your stack trace not the error. The error is in red. Even without seeing the exact error though I can roughly guess which line is causing the problem though:

hit.Parent.UpperTorso.Blood1.Rate = 100

Rate isn’t a property of Blood1 so this is invalid. Perhaps you meant to set the Value of Rate (Rate.Value) or an attribute instead (Blood1:SetAttribute → Rate). It’d help a whole lot more if you also provided the hierarchy of UpperTorso as a screenshot so we can see the objects but I’ll assume you’re using a NumberValue or IntValue for Rate.

1 Like

e2

The rate value is working and being changed by that line of code, but I don’t know why it randomly stops working

Thanks for the information. Rate is a valid property of a ParticleEmitter so my previous post is incorrect and setting the Rate of a ParticleEmitter is valid. Could you provide the actual error you’re facing as well as the code on the line where its happening? You gave only the stack trace not the error.

1 Like

There is no error. That stack trace seems like the error. It shows up whenever the barbed wire stops working

Stack traces aren’t errors. You need to do some more debugging on your end or provide more screenshots and context for this error. I tried reproducing the scenario by dropping this code into a part in Studio and I’m getting errors as well as stack traces.

image

^ This error comes from Line 14 of my repro (line is below) assuming that the hit’s parent has a child named Humanoid which is false when my accessory’s handle touches the part and thus errors, which you could fix by checking if there’s a Humanoid first with FindFirstChild before running it.

hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 4

Debugging Tools on the Developer Hub

1 Like

well when the player died from the barbed wire, I got this error

The line 18 is the hit.Parent.UpperTorso.Blood1.Rate = 0

Are you currently using an R6 avatar? Because the “Upper Torso” joint is exclusive to R15 avatars. If so use “Torso” instead as that is the torso joint used by R6 avatars.

1 Like
local Players = game:GetService("Players")

local BarbedWire = script.Parent
local BarbedWireModel = BarbedWire.Parent
local Wood = BarbedWireModel.Wood
local Hurt = Wood.HurtPlayer

local Debounce = false

local function BarbedWireContacted(Hit)
	if not Debounce then
		local HitModel = Hit:FindFirstAncestorWhichIsA("Model")
		if HitModel then
			local HitPlayer = Players:GetPlayerFromCharacter(HitModel)
			if HitPlayer then
				Debounce = true
				local HitHuman = HitModel.Humanoid
				local HitTorso = nil
				if HitHuman.RigType == Enum.HumanoidRigType.R6 then
					HitTorso = HitModel.Torso
				elseif HitHuman.RigType == Enum.HumanoidRigType.R15 then
					HitTorso = HitModel.UpperTorso
				end
				Hurt:Play()
				local Blood = HitTorso:FindFirstChild("Blood1")
				if Blood then
					Blood.Rate = 100
					task.delay(1.5, function()
						Blood.Rate = 0
					end)
				end
				task.wait(0.5)
				HitHuman.Health -= 4
				task.wait(0.5)
				Debounce = false
			end
		end
	end
end

BarbedWire.Touched:Connect(BarbedWireContacted)

I am using R15 Characters

at least 3.0 (ignore that)

You should do if Debounce == false then also check if the player the block is touching is really alive, so you don’t get any errors

sorry i’m a bit late, but the same thing happened. A blue line showed up like an “error” and everything stopped working

Spelling mistake on my part, try now (I’ve edited the original post).

same thing:

Forgot to push submit, my bad, now should be good.