function Explode(t)local Z=Instance.new("\069\120\112\108\111\115\105\111\110",workspace)Z.ExplosionType=Enum.ExplosionType.NoCraters Z.Position=t.Position Z.BlastRadius=config.ExplosionRadius.Value t:Destroy()script.Parent:remove()end script.Parent.Throw.OnServerEvent:connect(function(t,Z)local u=Vector3.new(tool.Handle.Position.X,0,tool.Handle.Position.Z)local B=Vector3.new(Z.X,0,Z.Z)local a=(u-B).magnitude local x=Z.Y-tool.Handle.Position.Y local A=AngleOfReach(a,x,config.GrenadeVelocity.Value)tool.Handle.Transparency=1 local b=tool.Handle:Clone()b.Parent=workspace b.Transparency=1 b.CanCollide=true b.CFrame=tool.Handle.CFrame b.Velocity=(CFrame.new(b.Position,Vector3.new(Z.X,b.Position.Y,Z.Z))*CFrame.Angles(A,0,0)).lookVector*config.GrenadeVelocity.Value spawn(function()if config.ExplodeOnTouch.Value then b.Touched:connect(function(t)if t.Parent~=tool.Parent and t.CanCollide then Explode(b)end end)else wait(config.FuseTime.Value)Explode(b)end end)wait(config.Cooldown.Value)tool.Handle.Transparency=1 end)
-- A simple function to explode a specified part
function Explode(part)
	local explosion = Instance.new("Explosion", workspace)
	explosion.ExplosionType = Enum.ExplosionType.NoCraters
	explosion.Position = part.Position
	explosion.BlastRadius = config.ExplosionRadius.Value
	part:Destroy()
	script.Parent:remove()
end

script.Parent.Throw.OnServerEvent:connect(function(player, mousePosition)
	local handlePos = Vector3.new(tool.Handle.Position.X, 0, tool.Handle.Position.Z) -- remove Y from the equation, it's not needed
	local mousePos = Vector3.new(mousePosition.X, 0, mousePosition.Z) -- ditto
	local distance = (handlePos - mousePos).magnitude -- Get the distance between the handle and the mouse
	local altitude = mousePosition.Y - tool.Handle.Position.Y
	local angle = AngleOfReach(distance, altitude, config.GrenadeVelocity.Value) -- Calculate the angle

	tool.Handle.Transparency = 1
	local grenade = tool.Handle:Clone()
	grenade.Parent = workspace
	grenade.Transparency = 1
	grenade.CanCollide = true
	grenade.CFrame = tool.Handle.CFrame
	grenade.Velocity = (
		CFrame.new(grenade.Position, Vector3.new(mousePosition.X, grenade.Position.Y, mousePosition.Z))
		* CFrame.Angles(angle, 0, 0)
	).lookVector * config.GrenadeVelocity.Value -- Throwing 'n stuff, it probably didn't need to be this long
	spawn(function()
		if config.ExplodeOnTouch.Value then
			grenade.Touched:connect(function(hit)
				if hit.Parent ~= tool.Parent and hit.CanCollide then -- Make sure what we're hitting is collidable
					Explode(grenade)
				end
			end)
		else
			wait(config.FuseTime.Value)
			Explode(grenade)
		end
	end)
	wait(config.Cooldown.Value)
	tool.Handle.Transparency = 1
end)
