I’m trying to make a bomb that sticks onto objects and players and then explodes through a weld, but every time I do the object just like teleports extremely off from the object that it hit… What am I doing wrong?
As you can see in the video, the bomb for some reason floated off of the wall before exploding or bounced off and then made a weld midair. What should I do?
Part of The Code That Creates The Weld
local touchedConnection
touchedConnection = bombClone.Touched:Connect(function(hit)
if user.Character then
if not user.Character:FindFirstChild(hit.Name, true) then
touchedConnection:Disconnect()
local weld = Instance.new("WeldConstraint")
weld.Part0 = bombClone
weld.Part1 = hit
weld.Parent = bombClone
newBomb:Explode(user, bombData, bombClone, false, true) -- the bomb explodes (vine boom).
end
end
end)
Full Code
--\\ Functions //--
function throwBomb(bombClone, targetPos)
local initialPos = bombHandle.Position
local distance = (targetPos - initialPos) -- The distance between targetPos and initialPos
local force = 150
local directionVector = bombClone.AssemblyMass * distance.Unit * force
local gravitationalForce = (bombClone.AssemblyMass * Vector3.new(0, workspace.Gravity * 0.5, 0))
bombClone:ApplyImpulse(directionVector + gravitationalForce)
end
activateBombRemote.OnServerEvent:Connect(function(user, mouseHitPos)
if not cooldown then
cooldown = true
local bombClone = bombHandle:Clone() -- The cloned version of the handle that eventually explodes.
bombClone.CanCollide = true
bombClone.CFrame = bombHandle.CFrame * CFrame.new(0, 2, 2) -- The offset for the bomb's position when spawned.
bombClone.Parent = workspace.Terrain.spawnedBombs
throwBomb(bombClone, mouseHitPos)
local newBomb = bombModule.createBomb() -- Inherites the bomb functions.
newBomb.bombType = "Sticky"
local touchedConnection
touchedConnection = bombClone.Touched:Connect(function(hit)
if user.Character then
if not user.Character:FindFirstChild(hit.Name, true) then
touchedConnection:Disconnect()
local weld = Instance.new("WeldConstraint")
weld.Part0 = bombClone
weld.Part1 = hit
weld.Parent = bombClone
newBomb:Explode(user, bombData, bombClone, false, true) -- the bomb explodes (vine boom).
end
end
end)
task.wait(bombData.cooldown)
cooldown = false
return false
end
end)