Hello there.
I’m creating a bomb for a PVP game and I’ve been confused where to start on lighting the bomb. I’m trying to make it so that when you first use the item, you’ll lit the bomb which will go on a countdown before exploding, dealing heavy damage to yourself and others around you unless you clicked twice where you’ll throw the bomb at your direction.
How can I make it so the bomb can explode if you haven’t thrown it yet?
Module Script
--//Services\\--
local PLRS = game:GetService("Players")
local DB = game:GetService("Debris")
--//Module\\--
local WeaponsModule = {}
--//Sword\\--
--N/A
--//Bomb\\--
local Thrown = false
function WeaponsModule.TickBomb(Bomb) --Ngl I actually just stole this from the actual bomb gear lol
Bomb.Attachment.ParticleEmitter.Enabled = true
local updateInterval = .4
local function Tick()
updateInterval = updateInterval * .9
end
while updateInterval > .1 do
wait(updateInterval)
Tick()
Bomb.Tick:Play()
end
--//Explosion\\--
Bomb["KABOOM!"]:Play()
local Explosion = Instance.new("Explosion",Bomb)
Explosion.Position = Bomb.Position
Explosion.BlastPressure = 80
Explosion.DestroyJointRadiusPercent = 0
--//Hitting
local Hits = {}
Explosion.Hit:Connect(function(OnHit)
local Character = OnHit:FindFirstAncestorWhichIsA("Model")
local Humanoid = Character and Character:FindFirstChildWhichIsA("Humanoid")
if Humanoid and not Hits[Character] then
Hits[Character] = true
Humanoid:TakeDamage(30)
--//Tagging
local IsPlayer = PLRS:GetPlayerFromCharacter(Character)
if IsPlayer then
local NewTag = Instance.new("ObjectValue",IsPlayer.Character.Humanoid)
NewTag.Name = "creator"
NewTag.Value = IsPlayer.Name
game:GetService("Debris"):AddItem(NewTag,10)
end
task.wait(2)
Hits[Character] = false
end
end)
Bomb.Transparency = 1
Bomb.Attachment.ParticleEmitter.Enabled = false
DB:AddItem(Bomb,3)
end
function WeaponsModule.ThrowBomb(Dir, Bomb, ThrowForce)
local AttachForce = Instance.new("Attachment",Bomb)
local LinearForce = Instance.new("LinearVelocity",Bomb)
Bomb.Orientation = Vector3.new(-90, 0, 0)
--Force stuff
LinearForce.Attachment0 = AttachForce
LinearForce.MaxForce = math.huge
LinearForce.VectorVelocity = Dir.LookVector * ThrowForce + Vector3.new(0,30,0)
game:GetService("Debris"):AddItem(LinearForce,.12)
end
return WeaponsModule
Local Script
--//Tool\\--
local Tool = script.Parent
local WeaponsModule = require(game:GetService("ReplicatedStorage").ModuleScripts.WeaponsModule)
--//Character\\--
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")
--//Functions\\--
local DB = false
local Throw = false
local HolsterAnim
Tool.Activated:Connect(function()
if DB then return end
DB = true
if not Throw then
Humanoid.WalkSpeed = 22
--//Lighting
local LitAnim = Character.Humanoid.Animator:LoadAnimation(Tool.LitBomb)
LitAnim:Play()
LitAnim.Stopped:Wait()
--//Holstering (?)
HolsterAnim = Character.Humanoid.Animator:LoadAnimation(Tool.Holster)
HolsterAnim:AdjustWeight(30)
HolsterAnim:Play()
task.wait(0.2)
DB = false
Throw = true
else
Humanoid.WalkSpeed = 16
HolsterAnim:Stop()
--//Throwing Bomb
local ThrowAnim = Character.Humanoid.Animator:LoadAnimation(Tool.Throw)
ThrowAnim:Play()
ThrowAnim:GetMarkerReachedSignal("ThrowBomb"):Connect(function()
Tool.Handle.Transparency = 1
Tool.RemoteEvent:FireServer()
end)
ThrowAnim.Stopped:Wait()
Throw = false
Tool.Handle.Transparency = 0
task.wait(1)
DB = false
end
end)
Tool.Equipped:Connect(function()
local IdleAnim = Character.Humanoid.Animator:LoadAnimation(Tool.Idle)
IdleAnim:Play()
Tool.Unequipped:Connect(function()
IdleAnim:Stop()
end)
end)