Log in to vote
3

# How do i make a pellet from a slingshot break buildings? [Unanswered]

Asked by
Marios2 360
7 years ago

I am trying to reprogram a slingshot so that, instead of damaging humanoids, it takes out parts out of buildings.

Is this script i added in correct in any way? Note:No errors in the script

connectionPart = pellet.Touched.Part:connect(onTouchedPart)

function onTouched(hit)
Part = hit
if Part~=nil then
tagPart(Part)
Part:BreakJoints()
else
connectionPart:disconnect()
end
end


### 1 answer

Log in to vote
0
Answered by
adark 5477
7 years ago

You're close, but you should try and test this yourself before asking here.

Just because the script editor shows no errors, it doesn't mean your code is bug free.

Anyways, here is the edited code:

connectionPart = pellet.Touched:connect(function(hit)
if hit then
tagPart(hit)
hit:BreakJoints()
connectionPart:disconnect()
end
end


I made this an anonymous function, since that is the only way I could think to have the function disconnect itself without using a form of debounce. This may or may not work as intended.

I removed the Part = hit line since it's unnecessary.

I removed the ~= nil because it's also unnecessary. (If hit is not nil, it will be 'truthy', so the if check will pass)

I removed the else because I assume you only want this to break a single part it hits.

By the way, this will still kill Players if it hits their characters. You'll have to add another check if you only want it to break the joints of specifically named Parts.

(BTW, use Tab instead of four spaces when writing code. It makes indentation easier to change.)

0
Won't work - http://imgur.com/aZL8J5d Marios2 360 — 7y