I’m writing a script that throws a bomb in the direction of the mouse cursor, but I don’t know how to do it, and it doesn’t work
Hope for the right solution please help!
local remote = game.ReplicatedStorage.bomb.bombevent
local player = game.Players.LocalPlayer
remote.OnServerEvent:Connect(function(plr, target)
local chr = plr.Character or plr.CharacterAdded:Wait()
local hrp = chr:FindFirstChild('HumanoidRootPart')
local b = game.ReplicatedStorage.bomb.Handle:Clone()
b.Parent = workspace
local bomb = b:Clone()
local GRAVITY_ACCELERATION = 196.2
local bodyForce = Instance.new('BodyVelocity', b)
bodyForce.Name = 'Antigravity'
bodyForce.Velocity = Vector3.new(0, b:GetMass() * GRAVITY_ACCELERATION, 0)
local spawnPosition = (chr.RightHand.CFrame * CFrame.new(2, 0, 0)).p
bomb.CFrame = CFrame.new(spawnPosition, target) --NOTE: This must be done before assigning Parent
bomb.Velocity = bomb.CFrame.lookVector * 10 --NOTE: This should be done before assigning Parent
bomb.Parent = game.Workspace
spawn(function()
while wait(0.05) do
bodyForce.Velocity = bodyForce.Velocity - Vector3.new(0,1,0)
end
end)
wait(0.3)
b.Touched:Connect(function(hit)
b["Explosions 9 (SFX)"]:Play()
local exp = Instance.new('Explosion', workspace)
exp.Position = b.Position
exp.BlastRadius = 9
b.CanTouch = false
wait(0.5)
b:Destroy()
end)
end)