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)
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.
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.
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.
^ 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.
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.
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)