Hello,
I’m trying to make a sticky bomb for my game, and even though Its pretty much finished, but I’m currently facing two issues.
-
The calculation for throwing the missile for some reason doesn’t really work when the camera is Infront of the player’s character.
-
The bomb for some reason bounces off of parts like buildings and then the bomb gets welded midair, causing it to just be frozen in the air and not dealing any damage to the building.
-
- The Ball also falls to the ground after like one second of it being in the air, and I was into the stay in the air while there’s a force on it.
Here’s the code.
client.lua
local MOUSE_ICON = "rbxasset://textures/GunCursor.png" -- Changes the mouse to the GunCursor Icon.
local RELOADING_ICON = "rbxasset://textures/GunWaitCursor.png" -- Changes the mouse icon to the Gun Wait Curso Icon.
local Player = game.Players.LocalPlayer
local Tool = script.Parent
local cooldown = false
local UserInputService = game:GetService("UserInputService")
local RemoteEvent = Tool:WaitForChild("RemoteEvent")
Tool.Equipped:Connect(function()
UserInputService.MouseIcon = MOUSE_ICON
end)
Tool.Unequipped:Connect(function()
UserInputService.MouseIcon = "rbxassetid://1"
end)
Tool.Activated:Connect(function()
if not cooldown then
cooldown = true
local character = Tool.Parent;
local humanoid = character:FindFirstChildOfClass("Humanoid")
local targetPos = game:GetService("Players").LocalPlayer:GetMouse().Hit.Position
local lookAt = (targetPos - character.Head.Position).Unit
UserInputService.MouseIcon = RELOADING_ICON
print(lookAt)
RemoteEvent:FireServer(lookAt)
task.wait(6)
UserInputService.MouseIcon = MOUSE_ICON
cooldown = false
end
end)
server.lua
local Tool = script.Parent
local Ball = Tool.Handle
local RemoteEvent = Tool:WaitForChild("RemoteEvent")
local tickSound = Instance.new("Sound")
tickSound.SoundId = "rbxasset://sounds\\clickfast.wav"
tickSound.Parent = script.Parent
local explosionSound = Instance.new("Sound")
explosionSound.SoundId = "rbxassetid://4612378521"
explosionSound.Parent = script.Parent
local blastRegion3L = 12/2 -- The Length of the Blast (Dividing all of the dimensions by 2 so that the region3 is not twice its size after making its size relative to the position)
local blastRegion3W = 12/2 -- The Width of the Blast
local blastRegion3H = 12/2 -- The Maximum height of the region3
local baseDamage = 35
function explode(bomb, user)
for i = 1, 3 do task.wait(.75)
tickSound:Play()
end
task.wait(1)
local explosionSoundClone = explosionSound:Clone()
explosionSoundClone.Parent = bomb
explosionSoundClone:Play()
local region3 = Region3.new(
bomb.Position - Vector3.new(blastRegion3L, blastRegion3H, blastRegion3W),
bomb.Position + Vector3.new(blastRegion3L, blastRegion3H, blastRegion3W)
) -- Creates a region3 that destroys any parts in the explosions radius.
local region3Visual = bomb.region3Visual:Clone()
region3Visual.CFrame = region3.CFrame
region3Visual.Parent = bomb
region3Visual.Transparency = .5
region3Visual.SelectionSphere.Transparency = .5
region3Visual.Size = region3.Size
local explosion = Instance.new("Explosion") -- The explosion instance
explosion.Parent = bomb
explosion.Position = region3Visual.Position
explosion.BlastRadius = 0
explosion.DestroyJointRadiusPercent = 0
explosion.BlastPressure = 900000
explosion.BlastRadius = blastRegion3L
local overlapParams = OverlapParams.new()
overlapParams.FilterDescendantsInstances = {region3Visual}
local parts = workspace:GetPartBoundsInBox(region3.CFrame, region3.Size, overlapParams)
explosion.Hit:Connect(function(Part)
if Part.Name == "HumanoidRootPart" then
local character = Part.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if player and player.Team ~= user.Team then
character:FindFirstChildOfClass("Humanoid"):TakeDamage(baseDamage)
if character:FindFirstChildOfClass("Humanoid").Health == 0 then
user.leaderstats.Kills.Value += 1
end
elseif player ~= user and player.Neutral == true then
character:FindFirstChildOfClass("Humanoid"):TakeDamage(baseDamage)
if character:FindFirstChildOfClass("Humanoid").Health == 0 then
user.leaderstats.Kills.Value += 1
end
end
end
end)
for i, v in pairs(parts) do
if v.Name == "Brick" then
v.Anchored = false
v.CanTouch = false
v.BrickColor = user.TeamColor
for i, constraint in pairs(v:GetChildren()) do
if constraint:IsA("Snap") or constraint:IsA("Weld") or constraint:IsA("WeldConstraint") then
constraint:Destroy()
end
end
task.delay(2, game.Destroy, v)
end
if v.Name == "GameBrick" then v.Name = "TaggedGameBrick" -- TaggedGameBricks are GameBricks in the game that have been effected by the bomb, while regular Bricks are just bricks you can destroy by default.
v.Anchored = false
v.CanTouch = false
user.leaderstats.Bricks.Value += 1 -- The total bricks the player has broken throughout the round.
user["T. Bricks"].Value += 1 -- The total bricks that the player has destroyed throughout there playtime
user.leaderstats.Studs.Value += .1 -- Increases the players currency (Studs) by 0.1.
v.BrickColor = user.TeamColor -- Changes the taggedBricks color to the local players team color to show that they have broken the part.
task.delay(2, game.Destroy, v) -- later deletes the part.
end
end
task.delay(3, game.Destroy, bomb)
local tween = game:GetService("TweenService"):Create(region3Visual, TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0), {
Transparency = 1
})
tween:Play()
local tween2 = game:GetService("TweenService"):Create(region3Visual.SelectionSphere, TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0), {
Transparency = 1
}):Play()
tween.Completed:Connect(function()
task.delay(4, game.Destroy, region3Visual)
end)
task.wait(.5)
end
RemoteEvent.OnServerEvent:Connect(function(player, direction)
local Character = Tool.Parent
local Player = game.Players:GetPlayerFromCharacter(Character)
local missile = Ball:Clone()
missile.Parent = workspace.Bombs
local spawnPos = Character.PrimaryPart.CFrame * CFrame.new(0, 0, -2.5)
missile:PivotTo(spawnPos)
missile.Velocity = direction * 200
local Connection
Connection = missile.Touched:Connect(function(hit)
if hit:IsDescendantOf(player.Character) == false and hit:IsDescendantOf(Tool) == false then
Connection:Disconnect()
missile.Anchored = true
local weld = Instance.new("WeldConstraint")
weld.Parent = missile
weld.Part0 = hit
weld.Part1 = missile
missile.Anchored = false
explode(missile, player)
end
end)
end)