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

How would I make it so players can only spawn one bomb at a time?

Hello.

I am currently trying to make this bomb tool that spawns a bomb to workspace. I have multiple obtainable bombs in my game and I only want one bomb to be able to be spawned at a time, and only be able to be placed once one has exploded. However, I am not really sure how to do that from a tool, and how to check if the bomb is already present in workspace, and if it is to not plant it.

I have tried to use values but it didn't seem to do the trick.

If I could get some help with this, it would be great!

Thanks!

1 answer

✓ Accepted answer

Alright, think of it like this. Your goal is to prevent the player from deploying a bomb while their bomb currently exists in the Workspace. Logically, you'd want to use an on-off switch (boolean debounce). You can take this one of two ways:

  1. Poll for the bomb to no longer exist.

  2. Use ChildRemoved to see when the bomb is removed from the Workspace.

Assuming you're going to poll for it, you should still use the on-off switch. This is because even though a loop would be running, a function call can run in a separate thread and would try to run simultaneously with the already running loop. This can result in the function yielding an error.

If you're going to use ChildRemoved, you need the on-off switch. Once the bomb has been deployed, the switch should be on. Once the bomb is removed from the Workspace, the switch should be off, allowing another bomb to be deployed.

I'll let you think of the code to use, since I just gave you the idea.

1 comment

0

Thanks, that worked!

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