Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is my NPC interacting with a non-collidable object?

Asked by 3 years ago
Edited 3 years ago

I have a npc that follows you around. I want to create a cylinder at certain intervals that is attached to the npc. When I try to do this, my boss interacts with my cylinder for a quarter of a second when canCollide is clearly disabled. The same thing happened to me when I imported a cylinder from blender and tried using that. However, any use of a plain "MeshPart" seems to not affect the npc. These two interactions only happen when I have my weld that welds between the new part and the npc. Here is the code that I am using:

local warning = Instance.new("Part")
warning.CanCollide = false
warning.Anchored = false

local mesh = Instance.new("SpecialMesh")
mesh.MeshType = Enum.MeshType.Cylinder
mesh.Parent = warning

warning.Size = Vector3.new(16, .1, 16)
warning.CFrame = CFrame.new(myChar.HumanoidRootPart.Position.X, 4, myChar.HumanoidRootPart.Position.Z)

warning.Name = "Warning"

warning.Parent = game.workspace
local weld = Instance.new("WeldConstraint")
weld.Part0 = myChar.Head
weld.Part1 = warning
weld.Parent = warning

warning:SetNetworkOwner()

1 answer

Log in to vote
1
Answered by
stef0206 125
3 years ago
local warning = Instance.new("Part")
warning.CanCollide = false
warning.Anchored = false
warning.Massless = true -- This is where the fix is

local mesh = Instance.new("SpecialMesh")
mesh.MeshType = Enum.MeshType.Cylinder
mesh.Parent = warning

warning.Size = Vector3.new(16, .1, 16)
warning.CFrame = CFrame.new(myChar.HumanoidRootPart.Position.X, 4, myChar.HumanoidRootPart.Position.Z)

warning.Name = "Warning"

warning.Parent = game.workspace
local weld = Instance.new("WeldConstraint")
weld.Part0 = myChar.Head
weld.Part1 = warning
weld.Parent = warning

warning:SetNetworkOwner()

You have to set the Part to Massless, otherwise Roblox will take it into account when calculating the center of mass.

Ad

Answer this question