So, in my workspace, I have a part that looks like this:
Part - Script - BodyVelocity
The script looks like this:
1 | Boop = script.Parent |
2 | function sayhi() |
3 | print ( "bruh" ) |
4 | end |
5 |
6 | Boop.Touched:Connect(sayhi) |
When I run the game, the part looks like this:
Part - Script - TouchInterest - BodyVelocity
The original part works as intended, but when my gun clones the Part to shoot it out, it doesn't copy the touchinterest meaning that my script can't print "bruh" because it can't detect when it is touched.
How do I get the touchinterest to be cloned as well?
If you want to clone a part I'd put it in ReplicatedStorage
, that's what the storage is for. Also you can put the .Touched
function inside of where your gun clones the part like so:
01 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
02 | local shootingPart = ReplicatedStorage:WaitForChild( "Part" ) |
03 |
04 | --// In your shooting function after you clone the part |
05 | local clone = shootingPart:Clone() |
06 | clone.Parent = workspace |
07 |
08 | clone.Touched:Connect( function () |
09 | print ( "bruh" ) |
10 | end ) |
or for the code above to be shorter since the "short cuts" are not needed
1 | local shootingPart = game.ReplicatedStorage:WaitForChild( "Part" ) |
2 |
3 | shootingPart:Clone().Parent = workspace |
4 |
5 | shootingPart.Touched:Connect( function () |
6 | print ( "bruh" ) |
7 | end ) |
we dont need all those shortcuts so i narrowed it down to a shorter code, does the exact same thing though