So,
I’ve been trying to make a sticky bomb that when thrown sticks to players and objects and then explodes, dealing x amount of damage.
Things that I want to achieve:
- Make the sticky bomb throwable.
- Make the sticky bomb stick.
- Allow players to throw the sticky bomb into the air (with a certain force).
How should I go about doing this with a tool?
I tried doing something today so the bomb could get thrown, but I got the error that the mouse was nil. What should I do?
function throwBomb(bombClone, mouse)
local initialPos = bombHandle.Position
local targetPos = mouse.Hit.Position
local distance = (targetPos - initialPos).Magnitude
local travelTime = 2
local force = distance * Vector3.new(0, workspace.Gravity * 0.5, 0)
bombClone:ApplyImpulse(force * bombClone.AssemblyMass)
end
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 UserInputService = game:GetService("UserInputService")
local activateBombRemote = script.Parent:WaitForChild("ActivateBomb")
Tool.Equipped:Connect(function()
UserInputService.MouseIcon = MOUSE_ICON
end)
Tool.Unequipped:Connect(function()
UserInputService.MouseIcon = ""
end)
Tool.Activated:Connect(function()
local cooldownTime = activateBombRemote:FireServer(player:GetMouse())
repeat task.wait() until cooldownTime == false
UserInputService.MouseIcon = RELOADING_ICON
UserInputService.MouseIcon = MOUSE_ICON
end)