Would this be a good idea for touch detections in general?

So, let’s say you have multiple baseparts you want to have events for getting touched. (e.g. killbricks)

Now you need to use a for loop/collectionservice to do that.

The problem is although being an efficient strategy, it uses up more memory right?

So would it be more effective to do this?

Character.HumanoidRootPart.Touched:Connect(function(hit)
print(hit)
end)

This I would assume take up less memory. And it’s quite simple to do, and works exactly the same. So should I do it? Good idea?

2 Likes

that looks very good i think its more efficient and takes less memory but
you are checking for HumRootPart There are more parts to check for like Legs/Arms/Head
if alot of things are touching the player it may fire the event alot
but yeah i think that is good

amnot sure of that you can wait until someone else respond

Usually the HRP is also touched, but yeah I’ll make sure to use a for loop on all the character’s baseparts. It would still be more effective in the long run though probably.

It depends on the game aswell, maybe some games will only have a few baseparts that need to be touched.

But obbies should probably use this sort of code all the time

1 Like

yeah am making an obby and i think i will use that method but i will wait for someone to respond amnot sure if it has any cons because i havnot seen anyone using it in a game before

It’s not necessarily bad but there aren’t many pros over just using collection service. First of all, there are different kind of kill bricks and generally you should handle killing / damaging the player on the server side.

A client could simply delete that function or hook it, defeating the whole purpose. Then again, normal kill bricks aren’t invincible to this kind of thing.

Lastly, you’d be using more memory client side- and you have a misunderstanding about CollectionService. No, kill bricks will not ruin your game and cause memory Armageddon. Though connecting a hit every time the player touches something and checking the name will cause issues.

So please, just use collection service. It’s better and less of a hassle.

1 Like

I would be doing it server-side, you just need a playeradded/characteradded event.

But with collectionservice you would be connecting an event to the function for each part, so lets say you have 100 parts. 100 events.

Whereas with just the character’s baseparts, you’re using way less memory.

Connections are very cheap on memory. As a test, I connected touched signals on 1,089 parts and the took up ~0.07mb of memory initially with a simple damage logic.

I was going to say that but you’re much better at explaining than me, thank you :sweat_smile:

You’re assuming your method would take a substantially less amount of memory. You, in your bout to find a better method than collection service, end up having to loop through the player and create 15 rbxscriptsignals that are all handled on the client.

Not to mention, you’d get the function fired every time it touches something. Sure, you’re obviously going to have an if statement blocking it from doing anything, but in my opinion it seems like a not-so-great way to deal with damages. Like I said, collection service does NOT use that much memory.

Oh alright, thanks for your help.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.