Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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.)

1 comment

0

This discussion is preserved as it was. New answers, comments, and votes are closed.