I am a pretty new coder making a ball game where the point is basically that, if you dash into another player/ball they get killed. So to make the ball I took an R6 dummy and inserted a sphere part. But when i try to use the regular Touched nothing happens. I was thinking maybe the part I used in the dummy doesnt count as a bodypart? Because I kind of just made it barely bigger than the dummy and made all the other body parts uncollidable and totally transparent.
So what I wanna do is kind of
01 | function (Touched) |
02 |
03 | if ThePartThatTouched = Game.Workspace.Map then |
04 | print ( "Map" ) |
05 | else |
06 | print ( "else" ) |
07 | if ThePartThatTouched = NameOfTheSphereIUsedInTheDummy |
08 | ThePartThatTouched:FindFirstChild( "Humanoid" ).Health = 0 |
09 | end |
10 | end |
11 |
12 | script.Parent.TouchesAnotherPart (Touched) |
Thank you very much for reading!
You could name each sphere the same as a player's name and check if the part's name is that, if so, do stuff.
Use the Part.onTouched event.
1 | YourPart.Touched:Connect( function (thePartThatHit) -- When YourPart is touched, run this function. Register the touching part as a variable called thePartThatHit. |
2 |
3 | end ) |
If a character touches YourPart, for example, thePartThatHit would be a body part such as LeftArm, Head, Torso, etc. From here we can locate the humanoid, whose parent is the character model.
1 | YourPart.Touched:Connect( function (thePartThatHit) |
2 | local humanoid = thePartThatHit.Parent:FindFirstChildOfClass( "Humanoid" ) |
3 |
4 | if humanoid then -- Confirming if indeed a Humanoid exists. If there isn't a Humanoid this variable will be nil (nonexistent), the part that touched is probably not a character. If it does, then continue |
5 | humanoid.Health = 0 -- Kills the humanoid |
6 | end |
7 |
8 | end ) |
Use the part:GetTouchingParts() function.
For example:
1 | local Part = script.Parent |
2 | local connection = Part.Touched:Connect( function () end ) --This allows it to detect parts touching it even if they are for example anchored and intersecting with the part. |
3 | local TouchingParts = part:GetTouchingParts() |
4 | for key, TouchingPart in pairs (TouchingParts) do |
5 | TouchingPart.Transparency = 1 --Do whatever you want to the TouchingPart variable to affect all parts touching the Part. |
6 | end |