Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make tool throw a grenade at what your looking at?

Hello, I've been trying to make a grenade tool for a while and the problem I've been running into is that the grenade only goes forward because it comes out of a part inside to tool. I was wondering if I could modify this script to make the grenade go where you're looking at.

local ReplicatedStorage = game.ReplicatedStorage
local Grenade = ReplicatedStorage:WaitForChild('US_Grenade')
local Muzzle = script.Parent:WaitForChild('Muzzle')
local VGrenade1 = script.Parent:WaitForChild('base')
local VGrenade2 = script.Parent:WaitForChild('head')
local VGrenade3 = script.Parent:WaitForChild('leaver')
local VGrenade4 = script.Parent:WaitForChild('pin')
local VGrenade5 = script.Parent:WaitForChild('ring')
Space = game.Workspace
local NewGrenade = Grenade:Clone()

script.Parent.Activated:Connect(function()
	wait(1.04)
	NewGrenade.Parent = Space
	NewGrenade.CFrame = Muzzle.CFrame
	NewGrenade.Velocity = Muzzle.CFrame.lookVector * 92
	game:GetService('Debris'):AddItem(NewGrenade,49)
	wait(0.1)
	script.Parent.Script:Destroy()
	VGrenade1.Transparency = 1
	VGrenade2.Transparency = 1
	VGrenade3.Transparency = 1
	VGrenade4.Transparency = 1
	VGrenade5.Transparency = 1
end)

Extra Info:

Example of what I'm thinking of: If you look down the grenade gets thrown down.

Script Type: Normal Script

ObjectType ~ the grenade: Meshpart not inside a model.

1 answer

✓ Accepted answer

Replace line 16 with

NewGrenade.Velocity = game.Workspace.CurrentCamera.CFrame.LookVector * 92

if you wanna do with where the mouse is looking at then

NewGrenade.Velocity = Mouse.Hit.LookVector * 92

10 comments

0

oh and make a mouse variable

0

Is this how you get the make a mouse variable just to double check: local position = mouse. Hit

0

local Mouse = game.Players.LocalPlayer:GetMouse()

0

Oh also I'm very sorry for this I messed up and said it was a localscript but its a normal script

0

I'm sure you can use a remote event to make it on server

0

So it gave this error: Players.itsbboy.Backpack.MKII.Script:11: attempt to index nil with 'GetMouse'

0

Again, you can use remote events and use a localscript for the activated event and a normal script for the remoteevent.

0

So I put it in a localscript and it now goes where I want it to go but the grenade objects scripts don't work anymore

0

Use remote events if you wanna do server sided.

0

Ok I took a bit but I got it to work. Thank you so much this helped a lot. Have a great day.

This discussion is preserved as it was. New answers, comments, and votes are closed.