Throwing a bomb by clicking on the left mouse button

So the question is how to make sure that when you click on the left mouse button, the player spawn in his right-hand bomb (just the usual model), then played animation and the bomb fell, and then exploded. And so he could do as many times as he wants, pressed the button threw the bomb it exploded, etc. But the main thing is that I don’t want this bomb to be in the player’s inventory or that he didn’t see it.

For input, you can use the GetMouse() method of the player or use the UserInputService. Either way, input should be handled on a client script. This script would also play the animation for the player.

Then, I would use a remote event to communicate between this client script with some server side script.
This server side script would handle showing the bomb in the player’s hand, then releasing it when the animation completes.

“I don’t want this bomb to be in the player’s inventory”
If you don’t want to use a tool for the bomb, you could always spawn in the bomb model when the input is received, position near the players hand and weld it to their hand. Alternatively, accessories could be used.

1 Like

To achieve the desired functionality in Roblox Studio, you can follow these steps:

  1. Create the Bomb Model:
  • Create a new model in Roblox Studio that represents the bomb.
  • Place the bomb model somewhere in the workspace but make it invisible so that the player cannot see it.
  1. Create the Bomb Explosion Animation:
  • Create an animation in Roblox Studio that represents the bomb explosion.
  • This animation should animate the bomb model, making it fall and explode.
  1. Implement the Bomb-Throwing Functionality:
  • In a script within a LocalScript object, listen for the left mouse button click event.
  • When the left mouse button is clicked, initiate the bomb-throwing sequence.
  • In the bomb-throwing sequence, perform the following steps:
    • Create a clone of the bomb model.
    • Set the clone’s CFrame to the player’s right hand position (you can use the HumanoidRootPart or RightHand part to determine the position).
    • Play the bomb explosion animation on the clone.
    • After the animation finishes playing, destroy the clone to clean up the scene.
  • Repeat this sequence as many times as the player wants by clicking the left mouse button.

Here’s a basic example of how the code might look:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local bombModel = workspace.Bomb -- Replace 'Bomb' with the actual name of your bomb model
local explosionAnimation = workspace.ExplosionAnimation -- Replace 'ExplosionAnimation' with the actual name of your explosion animation

local function throwBomb()
    local clone = bombModel:Clone()
    clone.Parent = workspace
    
    clone:SetPrimaryPartCFrame(player.Character.RightHand.CFrame)
    
    local animation = clone:FindFirstChild("Animation") -- Replace 'Animation' with the actual name of the animation within the bomb model
    
    -- Play the bomb explosion animation
    animation:Play()
    
    -- Wait for the animation to finish playing
    animation.Stopped:Wait()
    
    -- Destroy the clone after the explosion animation finishes
    clone:Destroy()
end

mouse.Button1Down:Connect(throwBomb)

Note: Make sure to replace 'Bomb', 'ExplosionAnimation', and 'Animation' with the actual names of your bomb model, explosion animation, and animation within the bomb model, respectively.

Remember to place this code inside a LocalScript object and have it in a location where it can be executed (e.g., StarterPlayerScripts). Also, ensure that the bomb model and explosion animation are correctly placed in the workspace hierarchy.

By following these steps, you should be able to achieve the bomb-throwing functionality you described, where the player spawns a bomb in their right hand, the bomb falls and explodes when the left mouse button is clicked, and the process can be repeated as desired.

And where should all these scripts I mean local, etc?