You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want to make a bomb gun, kind of like this:
What is the issue? Include screenshots / videos if possible!
I don’t know how to make this.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried making an explosion on the player when they mouse.Button1Down with the gun out.
I would suggest working up to making something like this, perhaps working on something less complicated to practice and learn. There are tutorials on the DevForum, and YouTube tutorials teaching how to make a gun. This wouldn’t be much different, you would just add an explosion at the point the bullet hits.
You could use a BodyForce object, and set the force upon the explosion. You could have a kind of “Algorithm” to figure out the force, and then apply it:
local explosionPos = Vector3.new(0,0,0) --Set to the actual explosion position, or use a variable you already have
local player = game.Players:WaitForChild("YourUsername")--Find the player however you want to, you could just iterate through all of the players.
local Debris = game:GetService("Debris")
local explosionPower = 100000
local function applyExplode(plr)
local character = plr.Character or plr.CharacterAdded:Wait() --Getting the character
local HRM = character:WaitForChild("HumanoidRootPart")
local newC = CFrame.lookAt(explosionPos, HRM.Position)
local rot = newC.LookVector
local dist = (explosionPos - HRM.Position).magnitude
local force = rot * (explosionPower / dist)
print(force)
local bodyF = Instance.new("BodyForce", HRM)
bodyF.Force = force
Debris:AddItem(bodyF, 2)
end
wait(4)
print("Exploding")
wait(1)
applyExplode(player)
This applies an “explosion” from the point 0,0,0. Set the player to yourself and try it out. You can tweak it however you need. If I were you, I’d put it in a server script with the explosions, and have a for loop run, calculating this for each player. This also does not do anything rotation wise, and it doesn’t turn the player into a ragdoll, both of which are things you may want.
If you have any other questions please let me know.