Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by
itsbboy 17
2 years ago
Edited 2 years ago

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

Log in to vote
0
Answered by 2 years ago

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
0
oh and make a mouse variable AProgrammR 398 — 2y
0
Is this how you get the make a mouse variable just to double check: local position = mouse. Hit itsbboy 17 — 2y
0
local Mouse = game.Players.LocalPlayer:GetMouse() AProgrammR 398 — 2y
0
Oh also I'm very sorry for this I messed up and said it was a localscript but its a normal script itsbboy 17 — 2y
View all comments (6 more)
0
I'm sure you can use a remote event to make it on server AProgrammR 398 — 2y
0
So it gave this error: Players.itsbboy.Backpack.MKII.Script:11: attempt to index nil with 'GetMouse' itsbboy 17 — 2y
0
Again, you can use remote events and use a localscript for the activated event and a normal script for the remoteevent. AProgrammR 398 — 2y
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 itsbboy 17 — 2y
0
Use remote events if you wanna do server sided. AProgrammR 398 — 2y
0
Ok I took a bit but I got it to work. Thank you so much this helped a lot. Have a great day. itsbboy 17 — 2y
Ad

Answer this question