How to make boarded cave explosion objective

I am making an objective in my game where you have to find some dynamite and explode a boarded up cave. (I want to Dynamite to be in the players backpack in order for the boards to disappear/explode)

I have the part down where you find the dynamite and be able to acquire it, but i don’t know how to script the part where you actually do the exploding.

Theres not any solutions on YT or anywhere else as on how to do this

Ask me for any screenshots if you’d like for this.

When the player interacts with the cave (say with a ProximityPrompt) and they have dynamite:

  1. Remove the dynamite from their inventory, place it on the boards
  2. Wait a few seconds, maybe add some fun visuals like a spark moving down the fuse
  3. Unanchor the boards or delete the joints connecting them to the cave
  4. Make them fly off
  5. Add the boards to Debris with Debris | Documentation - Roblox Creator Hub to delete them after a few seconds

(2) could be done with an Explosion | Documentation - Roblox Creator Hub with it’s JointRadiusPercent set to 0, or by manually randomizing the board’s velocities like:

local boards = {} -- fill that out
local VEL = 100
for _, b in pairs(boards) do
    boards.Velocity = VEL * Vector3.new(math.random(), math.random(), math.random())
end
1 Like

Thanks for the Tip, but I am fairly new to roblox code and I don’t know how I would be able to do some of that, is there any video tutorials, or others that you can direct me to so I would be able to learn this?

The links I put all have lots of examples (tutorials + code) that you can follow.

Which parts other than those three are you having trouble with?

I am mostly having trouble with how I am actually going to implement the actual dynamite tool into this, like how I am going to code where whenever the player interacts with the dynamite, it puts the dynamite onto the boards or the unanchoring of the boards after it explodes

How does this part that you already have work?

I am able to make it to where the player clicks a model of dynamite and it puts it into their inventory, but other than that, the dynamite does not do anything besides you being able to hold it

That’s a good start!

The first step is the interaction.

Try adding a proximity prompt (tutorial: Proximity Prompts | Documentation - Roblox Creator Hub) to the cave entrance.

As a first step, see if you can just get it to print “has dynamite” or “doesn’t have dynamite” when the player interacts with it.

(There are other ways to do interaction, but a proximity prompt seems to fit the bill here)

Ok, I tried to do that and I got the proximity Prompt to work, and I did half of the code, but I dont know how to do the rest (game prints if player has dynamite or not when you interact with the prompt.)

This is the code I have so far:

local ToolName = game.ReplicatedStorage.TNT

	if Player.Backpack:FindFirstChild(ToolName) then
		print("Player has dynamite in backpack!")
	else
		print("Player does not have dynamite in backpack!")
	end
end)

end)

Also, was I supposed to put the script into the proximity prompt or do I put it somewhere else?

You can put the script wherever you want. The proximity prompt seems like a good enough place.

That seems like a good start, you just need a .Name at the end of your ToolName line (or just say local ToolName = "TNT").


P.S. you can post code on here by surrounding it with three backticks
```
like this
```
so it shows up

like this

Also I think you missed a few lines of code when you copy pasted but I’m assuming this is inside a proximity prompt event.

The script does not work for me, when I interact, it does not print anything

Can you post the entire script?

local ToolName = game.ReplicatedStorage.TNT


		if Player.Backpack:FindFirstChild(ToolName) then
			print("Player has dynamite in backpack!")
		else
			print("Player does not have dynamite in backpack!")
		end
	end)

end)

That’s the same thing you posted before. Did you read the tutorial? You’re missing a few parts here, for example the PromptTriggered:Connect part.

Also repeating what I said before:

Sorry about that, I didn’t see the entire tutorial, does this look good now?

local Tool = game.ReplicatedStorage.TNT.Name
local Promt = script.Parent:WaitForChild("ProximityPrompt")

Promt.Triggered:Connect(function(Player)
	if Player.Backpack:FindFirstChild(Tool) then
		print("player has dynamite")
	else
		print("player does not have dynamite")
	end
	
end)

Assuming your hierarchy looks like

Part
|- Script
|- ProximityPrompt

Yes, that looks better, nice :slight_smile: Does it print?

Your next step is to remove the dynamite from their inventory if they have it, and place dynamite on the boards.

The removing is easy (just call Destroy() on the tool in the backpack)

You have some options for placing the dynamite. You could:

Uhh so it does not print? I don’t know what I did wrong, I tried doing the script on a local and regular script but no matter what I do, I does not print.

It works fine for me.

image

image

image

(Note that the dynamite has to be in the player’s backpack on the server, not just the client. I tested this by using the “Start” button here:

image

And copied the TNT tool on the server window instead of the client

image
)

oh wait, I see what I did wrong here lol. I put the script Inside the Proximity prompt instead of it being just in the part, it works fine now.

Alright, so the next thing is removing an item from the players backpack, I can guess on how to do that, but I still might need help. Sorry, I am pretty new to Lua