Your problem is here:
Try FindFirstChild
. The method FindFirstChildWhichIsA
is the equivalent of looping through a GetChildren
table and running IsA
on each object, returning the first match. It’s supposed to find an object of a base class, rather than a name.
You should also be using the new WeldConstraint
rather than the original weld because it’s easier to use, without having to mess with C0
or C1
properties. I couldn’t get the object to float in front of me with the original weld either.
I can see this line
ParticleMaker.CFrame = CFrame.new(ParticleMaker.Position) + Vector3.new(0, 0, -50)
is probably not what you meant to do. This code just puts the particle maker at 0, 0, -50
because CFrame.new(ParticleMaker.Position)
is initially at 0, 0, 0
. I think you meant to put it 50 studs in front of the torso.
I suggest you add a debounce to this Touched
listener as well. If you know Touched
well, then you know how spammy it can be.
Here is the code with all of these issues fixed. It uses a WeldConstraint
, spawns the part 50 studs in front of you, and has a 3 second debounce for each character.
local region = script.Parent
local Debounce = {}
local function onPartTouched(otherPart)
local humanoidroot = otherPart.parent:FindFirstChild("HumanoidRootPart")
if humanoidroot and not Debounce[humanoidroot] then
Debounce[humanoidroot] = true
local ParticleMaker = Instance.new("Part")
local weld = Instance.new("WeldConstraint")
weld.Part0 = ParticleMaker
weld.Part1 = humanoidroot
weld.Parent = ParticleMaker
ParticleMaker.CFrame = humanoidroot.CFrame + (humanoidroot.CFrame.LookVector * 50)
ParticleMaker.Parent = workspace
wait(3)
Debounce[humanoidroot] = nil
end
end
region.Touched:Connect(onPartTouched)
One issue remains, however… https://gyazo.com/3f0b7b430b7546b3eda7956632b29df4
Welding anything to the character, or even just having unwelded parts descend from the character, has always caused issues like this for me with varying degrees of effect. I don’t really know how to solve this particular issue. If welds do this and there’s nothing that can fix it, the only solution I can think of would be to just have an anchored part constantly refresh its position to be 50 studs in front of the torso.