-
What do you want to achieve? Keep it simple and clear!
I want to have 2 parts of the same name not be able to touch each other (as in touch events). -
What is the issue? Include screenshots / videos if possible!
I’ve tried making it so that when the part of the same name touches a part of the same it will ignore it, aka, not fire anything. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Tried using return end, and setting a collision group. But collision groups work with collison, not being able to touch.
Well, an if statement would work here.
local part = --part
part.Touched:Connect(function(hit)
if hit.Name ~= part.Name then
--not the same name
end
end)
I’ve done this multiple times, each in different ways. I just retested it too, still didn’t work.
Did you try putting in a print statement and see what print(hit.Name, part.Name) prints out? Make sure the parts actually have the same name?
make them the same collision group and disable collision allowed in parts of the same group
This simply doesn’t work. It wasn’t what I was wondering either. I was asking about 2 parts touching (touch events) so this doesn’t do anything.
For context, what I am trying to do is make something that fires a “bullet” towards the player. When it hits a part or the player it expands and destroys. The problem is, if it touches another “bullet” it will set off a chain reaction and it will not be able to get anywhere near the player.
Could we see your code? Also, I would do what @quakage says and add some print statements to test it out and see what’s happening. Without your code, there is honestly not much we can do to help.
For me, if you’re using raycasts, then I would just check the raycast result.
For instance, take a look at this sample code:
local raycast_result = workspace:Raycast(origin, direction, ray_params)
if raycast_result and raycast_result.Instance then
local i = raycast_result.Instance
if i.Parent:FindFirstChild("Humanoid") then
--take damage
elseif i.Name == "Bullet" then --if you wanted more accuracy, you can create a string attribute for the class and then check it from there
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bv.P = 1250
bv.Velocity = Vector3.new(412, 4050501, 0) --i'm guessing you wanted the bullets to fly somewhere random, if so this is how you would do it // you can change these numbers
end
end
Just so you know, Body Velocity is deprecated, so if you wanted to you could also the parts velocity or insert a Linear Velocity.
I think this is what you are looking for:
local bullet = script.Parent
bullet.OnTouch:Connect(function(otherPart)
if otherPart.Parent:FindFirstChild("Humanoid") then -- it is a character
-- bullet has hit a character
end
end)
Nevermind, thank you all. I figured it out. I just had to put a return end thing near the top of the touch event.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.