Scripting help i don't know if its possible though

hello so my problem is that i want something like a part’s touch function to only work on a special or like some parts for example like the touch function only fires/connects when it’s touching an part that is not named like that part

if your confused i just want to tell you that this script below works but im not looking for a script like that.

local part = script.Parent
part.Touched:Connect(function(p)
if p.Name == "aye" then
print("Special Part")
end
end)

what am trying to achieve:
i am trying to achieve a system where .Touched function will only work when it touched a part that is named “epic” or something like that with special properties or whatsoever.

3 Likes

I honestly don’t understand what you’re explaining but I’m guessing it’s something like this?

--//Variables
local Part = workspace.Part

--//Functions
Part.Touched:Connect(function(hit)
	if hit.Name == "Epic" then
		print("Special part")
	end
end)
1 Like

i’ve already mentioned its not like that, what i meant is like the touch function for the part will only connect if the part has a special property or is named something

1 Like

I’m sorry but can you rephrase that? Something like this?

--//Variables
local Part = workspace.Part

--//Functions
Part.Touched:Connect(function(hit)
	if Part.Name == "Epic" then
		print("Special part")
	end
end)

no it’s not like that I’ve already mentioned it above, I mean i don’t know if what i’m trying to achieve is possible but if it is it would be good.

I’m trying to make it like when it touched another part the .Touched connection in the script wont connect but when it’s touching a part with special property or named something like “epic” it will go through the connection process like this

part.Touched:Connect(function()
print("part is names Epic")
end)

that’s my first thing i’m trying to achieve idk if its possible but here’s a question:
what’s a good script where it’s like touch function but not laggy when 10 mobs touch each other the game just lags

Can you show the script you use for this?

1 Like

its just .touched without any debounce or something but if i add debounce and when it touches the water there’s a chance it’ll glitch out and if it glitches out it will no longer spawn back

1 Like

I think I get what you mean.

Instead of having every single touched part fire the touched event, you only want the special parts to fire it?

yes, that’s exactly I wanted. this is because so that when it touched the cliff it tps directly back to its original position but then again when it touches other parts with 10 mobs it lags, but yea that’s what im trying to achieve.

also question, how do i add something from a table like this:

local tableer = {
["sword"] = 13 -- damage
}

i want to add something like that to a table so it would turn out like this then

local tableer = {
["sword"] = 13, -- damage
["red sword"] = 353 -- damage
}

You need to use a collision group.
Have the cliff be in a group, and only allow your part to collide with the cliff group.

for the table you would do…

tableer["red sword"] = 353
2 Likes

even with collision group it still detects as if it touched the same part of the other part with the same collision group and turning cantouch off would make the it worse

the link you have provided doesn’t help at all as it’s only about collisions not including .touched events also im doing this on a humanoidrootpart so i can’t turn can collide off

1 Like

I thought if they were in a different collision group, and were not allowed to collide then it would not fire a touched event. However I did not test this.

So what are all the other parts you are colliding with that is causing lag?
You said you wanted to be able to .Touched with the cliff, but not the other parts. What are all the other parts?

1 Like

Rename the special parts ‘Special Part’ or add a value (like a boolean) in them and check for it.

You could adjust @Katrist’s script

Or you could put the special parts in a folder and sort through those to see if the part which hit it was in the special parts folder

1 Like

im not looking for this what i want to achieve is to only let the touch function fire when it touches a special part im sure you are confused as to what i am saying it but try to understand it and you will know.

something similar to the script u provided but like this

-- this line will only work & will only do a connection processes if it touches a special part and if it doesn't it won't do the print at all
Part.Touched:Connect(function(hit)
print("touching special part")
end)

however i am not sure at all if it is possible to do

1 Like

Your example 100% will work. There is a property of workspace called “TouchesUseCollisionGroup”. As long as that is set to true, it will be fine.

i haven’t tested that out but then again if i do it would end up ruining the other touch function since there’s dozens, it would be a hassle if i will do that. it’d be good if there were other ways with lesser workload

1 Like

and if i do that the mobs will no longer have their collision set to false to the players since its 2 separate collision groups, so it still doesn’t help

1 Like