I want to make a time bomb spawn inside my game but for some reason it spawns at a weird location, i’ve made the normal bomb and it works just fine. it spawns in front of the player.
Here’s a video of the bug:
tool.Activated:Connect(function()
if not projectilemode then
if not R then
if not db then
timeractive = true
db = true
local bomb = script.Parent.Handle:Clone()
A.BombFuse.Looped = true
A.BombFuse:Play()
bomb.Anchored = false
bomb.Parent = workspace
bomb.CanCollide = true
if timeractive then
repeat
wait(1)
timer -= 1
until timer == 0 or not timeractive
end
if timer == 0 then
A.BombFuse:Stop()
createExplosion(bomb)
A.ExplosionSFX:Play()
bomb:Destroy()
wait(.1)
timer = 2
end
wait(1)
db = false
end
else
if not db then
print("test")
db = true
local bomb = Handle2:Clone()
bomb.Anchored = false
bomb.Parent = workspace
bomb.CanCollide = true
task.wait(1)
db = false
end
end
else
--ignore these
if not R then
script.Parent.Handle.Transparency = 1
caster.LengthChanged:Connect(onLengthChanged)
caster.RayHit:Connect(onRayHit)
fireRE.OnServerEvent:Connect(function(player,mousepos)
fire(player,mousepos)
end)
else
print("TimeBomb G")
end
end
end)
tool.Activated:Connect(function()
if not projectilemode then
if not R then
if not db then
timeractive = true
db = true
local bomb = script.Parent.Handle:Clone()
A.BombFuse.Looped = true
A.BombFuse:Play()
bomb.Anchored = false
bomb.Parent = workspace
bomb.CanCollide = true
bomb.CFrame = script.Parent.Handle.CFrame
if timeractive then
repeat
wait(1)
timer -= 1
until timer == 0 or not timeractive
end
if timer == 0 then
A.BombFuse:Stop()
createExplosion(bomb)
A.ExplosionSFX:Play()
bomb:Destroy()
wait(.1)
timer = 2
end
wait(1)
db = false
end
else
if not db then
print("test")
db = true
local bomb = Handle2:Clone()
bomb.Anchored = false
bomb.Parent = workspace
bomb.CanCollide = true
bomb.CFrame = Handle2.CFrame
task.wait(1)
db = false
end
end
else
--ignore these
if not R then
script.Parent.Handle.Transparency = 1
caster.LengthChanged:Connect(onLengthChanged)
caster.RayHit:Connect(onRayHit)
fireRE.OnServerEvent:Connect(function(player,mousepos)
fire(player,mousepos)
end)
else
print("TimeBomb G")
end
end
end)
local function createExplosion(bomb)
local explosion = Instance.new("Explosion")
explosion.Position = bomb.Position
explosion.Parent = workspace
explosion.BlastRadius = math.random(10,30)
explosion.BlastPressure = math.random(1,10)
end
it works for the normal bomb for the first time but when i change it to the timedbomb it doesnt
also here’s the script to change the bomb
local UIS = game:GetService("UserInputService")
local ModeRE = script.Parent.ProjectileMode
local CD = false
local CD2 = false
local ProjectileMode = false
local TimeBomb = false
local TimeBombRE = script.Parent.TimeBomb
local tool = script.Parent
local Fire = script.Parent.FireProjectile
local mouse = game.Players.LocalPlayer:GetMouse()
local switchmode
local player = game.Players.LocalPlayer
local char = player.Character
local ActivateRE = script.Parent.BombActivate
local Ultimate = false
local UltReq = true
tool.Equipped:Connect(function()
switchmode = UIS.InputBegan:Connect(function(input, gameprocessed)
if not gameprocessed then
--ignore these
if input.KeyCode == Enum.KeyCode.G then
if CD == false then
if ProjectileMode == false then
CD = true
ProjectileMode = true
ModeRE:FireServer()
wait(5)
CD = false
else
CD = true
ProjectileMode = false
ModeRE:FireServer()
wait(5)
CD = false
end
end
elseif input.KeyCode == Enum.KeyCode.R then
if not CD2 then
if not TimeBomb then
print("#")
TimeBomb = true
CD2 = true
TimeBombRE:FireServer(TimeBomb)
task.wait(5)
CD2 = false
else
print("!")
TimeBomb = false
CD2 = true
TimeBombRE:FireServer(TimeBomb)
task.wait(5)
CD2 = false
end
end
elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
if TimeBomb then
ActivateRE:FireServer()
end
--ignore these
elseif input.KeyCode == Enum.KeyCode.U then
if not Ultimate then
if UltReq then
Ultimate = true
print("Ultimate")
task.wait(100)
Ultimate = false
end
end
end
end
end)
end)
tool.Unequipped:Connect(function()
switchmode:Disconnect()
end)
tool.Activated:Connect(function()
if ProjectileMode == true then
local mousepos = mouse.Hit.Position
Fire:FireServer(mousepos)
end
end)
also here’s the full script
local tool = script.Parent
local db = false
local timer = 2
local timeractive = false
local modeRE = script.Parent.ProjectileMode
local projectilemode = false
local fastcastredux = require(game:GetService("ReplicatedStorage").Assets.Module.FastCastRedux)
local partcache = require(game:GetService("ReplicatedStorage").Assets.Module.PartCache)
local fireRE = script.Parent.FireProjectile
local debris = game:GetService("Debris")
local A = require(game:GetService("ReplicatedStorage").Assets.Module.Assets)
local TimeBombRE = script.Parent.TimeBomb
local R = false
local Handle2 = game:GetService("ReplicatedStorage").TimeBomb
local Handle3 = game:GetService("ReplicatedStorage").Bomb
local ActivateRE = script.Parent.BombActivate
----projectile mode
local ammo = 3
local reloading = false
local normdamage = 40
local caster = fastcastredux.new()
---------------
TimeBombRE.OnServerEvent:Connect(function(player,TimeBomb)
R = TimeBomb
if R then
game:GetService("Debris"):AddItem(script.Parent.Handle,0)
local TB = Handle2:Clone();TB.Parent = tool;TB.Name = "Handle"
else
game:GetService("Debris"):AddItem(script.Parent.Handle,0)
local B = Handle3:Clone();B.Parent = tool;B.Name = "Handle"
end
end)
local function createExplosion(bomb)
local explosion = Instance.new("Explosion")
explosion.Position = bomb.Position
explosion.Parent = workspace
explosion.BlastRadius = math.random(10,30)
explosion.BlastPressure = math.random(1,10)
end
local function normHit(hum)
hum:TakeDamage(normdamage)
end
local function reload()
if reloading then return end
reloading = true
wait(5)
ammo = 6
reloading = false
end
local bulletfolder = workspace.BulletFolder
local bulletTemplate = script.Parent.Handle:Clone()
bulletTemplate.Anchored = true
bulletTemplate.CanCollide = false
local bulletcache = partcache.new(bulletTemplate,100,bulletfolder)
local castparams = RaycastParams.new()
castparams.FilterType = Enum.RaycastFilterType.Exclude
castparams.IgnoreWater = true
tool.Equipped:Connect(function()
castparams.FilterDescendantsInstances = {tool.Parent}
end)
local castbehavior = fastcastredux.newBehavior()
castbehavior.RaycastParams = castparams
castbehavior.Acceleration = Vector3.new(0,-(workspace.Gravity*.3),0)
castbehavior.AutoIgnoreContainer = true
castbehavior.CosmeticBulletContainer = bulletfolder
castbehavior.CosmeticBulletProvider = bulletcache
local function onRayHit(cast,result,velocity,bullet)
local hit = result.Instance
createExplosion(bullet)
local char = hit:FindFirstAncestorWhichIsA("Model")
local hum = char:FindFirstChild("Humanoid")
if char and hum then
normHit(hum)
end
debris:AddItem(bullet,.01)
end
local function onLengthChanged(cast, lastPoint, direction, length, velocity, bullet)
if bullet then
local bulletlength = bullet.Size.Z/2
local offset = CFrame.new(0,0,-(length - bulletlength))
bullet.CFrame = CFrame.lookAt(lastPoint, lastPoint + direction):ToWorldSpace(offset)
end
end
local function fire(player,mousepos)
if not db then
if ammo > 0 and not reloading then
db = true
local origin = script.Parent.Handle.FirePoint.WorldPosition
local direction = (mousepos - origin).Unit
caster:Fire(origin,direction,100,castbehavior)
ammo -= 1
wait(1)
db = false
else
reload()
end
end
end
modeRE.OnServerEvent:Connect(function()
if projectilemode == false then
projectilemode = true
else
projectilemode = false
script.Parent.Handle.Transparency = 0
end
end)
--drop bomb
tool.Activated:Connect(function()
if not projectilemode then
if not R then
if not db then
timeractive = true
db = true
local bomb = script.Parent.Handle:Clone()
A.BombFuse.Looped = true
A.BombFuse:Play()
bomb.Anchored = false
bomb.Parent = workspace
bomb.CanCollide = true
bomb.CFrame = script.Parent.Handle.CFrame
if timeractive then
repeat
wait(1)
timer -= 1
until timer == 0 or not timeractive
end
if timer == 0 then
A.BombFuse:Stop()
createExplosion(bomb)
A.ExplosionSFX:Play()
bomb:Destroy()
wait(.1)
timer = 2
end
wait(1)
db = false
end
else
if not db then
print("test")
db = true
local bomb = Handle2:Clone()
bomb.Anchored = false
bomb.Parent = workspace
bomb.CanCollide = true
bomb.CFrame = Handle2.CFrame
task.wait(1)
db = false
end
end
else
--ignore these
if not R then
script.Parent.Handle.Transparency = 1
caster.LengthChanged:Connect(onLengthChanged)
caster.RayHit:Connect(onRayHit)
fireRE.OnServerEvent:Connect(function(player,mousepos)
fire(player,mousepos)
end)
else
print("TimeBomb G")
end
end
end)