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

Destroying an object created in another script?

Hey, I just made a cannon. In one script, the cannonball (located in ServerStorage) is cloned and given velocity, and inside the cannonball there is a script causing it to explode when it hits something. However, I want the cannonball to disappear when it hits something. I can only figure out how to destroy the "original" cannonball inside ServerStorage.

Here are the scripts:

Cannonball creation: https://pastebin.com/P8y9Gecs

Explosion: https://pastebin.com/QKxFLnj6

2 answers

✓ Accepted answer

On your “Cannonball creation” script, you’re only cloning the cannonball once. Once that clone is destroyed, the script will error as it cannot find the cloned cannonball. Plus, I don’t see anything in your script that destroys anything, so I’m confused on how you managed to destroy the “original” cannonball.

Anyways, this is all you have to do :

  • Put line 3 from the creation script INSIDE the function.
  • Add Cannonball:Destroy() into the last line of the function in the explosion script.
  • Change “mouseClick” into “MouseClick” and change “:connect” into “:Connect”.

Putting line 3 into the function will clone the cannonball every time the function runs, instead of once. Adding Cannonball:Destroy() inside the function on the explosion script will destroy the cannonball as soon as the cannonball gets touched.

The only thing I'm going to say is use global variables (_G) but it must be on the same client or server (meaning if it's a Script then it must be a Script otherwise a LocalScript)

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