I am begginer scripter,
I want to make a grenade launcher everything’s been great so far but I just hit a roadblock.
The way that it works is that you start charging by holding mouse and when you release all of the accumulated grenades will start being shot.
I have already looked for solutions, but for some reason the grenade that I put on replicated storage does not execute the script attached to it, and manipulating CFrame with LookVector from the variable of the dupplicated grenade only affects it initial position.
What I want to achieve is for the grenades to be shot with an initial velocity with physics but I can’t find anything like that
Here’s my code
local tool = script.Parent
local handle = tool:WaitForChild(“Handle”)
wait(1)
local player = script.Parent.Parent.Parent
local gui = player.PlayerGui
local ammoGui = gui.GrenadeLauncher
local character = player.Character
local ammo = script.Parent.Ammo.Value
local reserve = script.Parent.Reserve.Value
local charging = false
local equipped = false
local activated = false
function updateGui()
ammoGui.Ammo.Text = ammo
ammoGui.Reserve.Text = reserve
end
tool.Activated:Connect(function()
activated = true
if not charging then
charging = true
for _ = 0, 50, 1 do
if not equipped or reserve == 0 or not activated then
break
end
ammo = ammo + 1
reserve = reserve - 1
wait(0.05)
updateGui()
end
charging = false
for _ = ammo,1,-1 do
if not equipped then
break
end
local pill = game.ReplicatedStorage.Pill:Clone()
pill.Parent = game.Workspace
pill.CFrame = tool.Handle.CFrame
ammo = ammo - 1
updateGui()
wait(0.1)
end
ammo = 0
updateGui()
end
updateGui()
end)
tool.Deactivated:Connect(function()
activated = false
end)
tool.Equipped:Connect(function()
equipped = true
ammoGui.Enabled = true
end)
tool.Unequipped:Connect(function()
equipped = false
ammoGui.Enabled = false
end)
Thanks in advance for your time!